blun-king-cli 9.1.234 → 9.1.236

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.
@@ -8,6 +8,7 @@ const ASSISTANT_MESSAGE_OFFLOAD_MARKER = '[Assistant message offloaded]';
8
8
  const ASSISTANT_TOOL_NARRATION_MIN_CHARS = 120;
9
9
  const ASSISTANT_TOOL_NARRATION_MARKER = '[Earlier completed tool-step narration compacted]';
10
10
  const ASSISTANT_POST_TELEGRAM_REPLY_MARKER = '[Earlier post-reply status compacted]';
11
+ const ASSISTANT_COMPLETED_SUBAGENT_PROMPT_MARKER = '[Earlier completed subagent task omitted; use its result below]';
11
12
  const SYNTHETIC_TOOL_ARGUMENT_MARKER = JSON.stringify({
12
13
  _blun_compacted: '[Old tool call arguments cleared]',
13
14
  });
@@ -123,6 +124,78 @@ function compactHistoricalPostTelegramReplyNarration(messages) {
123
124
  return changed ? projected : messages;
124
125
  }
125
126
 
127
+ function completedSubagentResultIds(messages) {
128
+ return new Set(messages.filter((message) => {
129
+ if (
130
+ message?.role !== 'tool'
131
+ || typeof message.toolCallId !== 'string'
132
+ || message.isError === true
133
+ || !Array.isArray(message.content)
134
+ || !message.content.every((part) => part?.type === 'text' && typeof part.text === 'string')
135
+ ) return false;
136
+ const text = message.content.map((part) => part.text).join('\n');
137
+ return /(?:^|\n)status:\s*completed(?:\s|$)/iu.test(text);
138
+ }).map((message) => message.toolCallId));
139
+ }
140
+
141
+ function compactCompletedSubagentCall(call, completedIds) {
142
+ if (
143
+ call?.name !== 'Agent'
144
+ || !completedIds.has(call.id)
145
+ || (typeof call.arguments !== 'string'
146
+ && (call.arguments === null || typeof call.arguments !== 'object' || Array.isArray(call.arguments)))
147
+ ) return call;
148
+
149
+ let args = call.arguments;
150
+ if (typeof args === 'string') {
151
+ try {
152
+ args = JSON.parse(args);
153
+ } catch {
154
+ return call;
155
+ }
156
+ }
157
+ if (args === null || typeof args !== 'object' || Array.isArray(args)) return call;
158
+ if (
159
+ typeof args.prompt !== 'string'
160
+ || args.prompt.length <= ASSISTANT_COMPLETED_SUBAGENT_PROMPT_MARKER.length
161
+ || args.prompt === ASSISTANT_COMPLETED_SUBAGENT_PROMPT_MARKER
162
+ ) return call;
163
+
164
+ const compactedArgs = {
165
+ ...args,
166
+ prompt: ASSISTANT_COMPLETED_SUBAGENT_PROMPT_MARKER,
167
+ };
168
+ return {
169
+ ...call,
170
+ arguments: typeof call.arguments === 'string'
171
+ ? JSON.stringify(compactedArgs)
172
+ : compactedArgs,
173
+ };
174
+ }
175
+
176
+ function compactHistoricalCompletedSubagentPrompts(messages) {
177
+ if (!Array.isArray(messages) || messages.length === 0) return messages;
178
+
179
+ const completedIds = completedSubagentResultIds(messages);
180
+ if (completedIds.size === 0) return messages;
181
+ const recentStart = Math.max(0, messages.length - ASSISTANT_MESSAGE_KEEP_RECENT_MESSAGES);
182
+ let changed = false;
183
+ const projected = messages.map((message, historyIndex) => {
184
+ if (
185
+ historyIndex >= recentStart
186
+ || message?.role !== 'assistant'
187
+ || !Array.isArray(message.toolCalls)
188
+ || message.toolCalls.length === 0
189
+ ) return message;
190
+ const toolCalls = message.toolCalls.map((call) => compactCompletedSubagentCall(call, completedIds));
191
+ if (toolCalls.every((call, index) => call === message.toolCalls[index])) return message;
192
+ changed = true;
193
+ return { ...message, toolCalls };
194
+ });
195
+
196
+ return changed ? projected : messages;
197
+ }
198
+
126
199
  function removeSyntheticToolArgumentFailures(messages) {
127
200
  if (!Array.isArray(messages) || messages.length === 0) return messages;
128
201
 
@@ -179,6 +252,8 @@ module.exports = {
179
252
  ASSISTANT_TOOL_NARRATION_MARKER,
180
253
  ASSISTANT_TOOL_NARRATION_MIN_CHARS,
181
254
  ASSISTANT_POST_TELEGRAM_REPLY_MARKER,
255
+ ASSISTANT_COMPLETED_SUBAGENT_PROMPT_MARKER,
256
+ compactHistoricalCompletedSubagentPrompts,
182
257
  compactHistoricalPostTelegramReplyNarration,
183
258
  createAssistantMessagePreview,
184
259
  isSyntheticToolArguments,
@@ -4,7 +4,21 @@ const {
4
4
  compactLegacyErrorMemoryReminder,
5
5
  } = require('./error-memory-performance-policy.cjs');
6
6
 
7
- const LATEST_ONLY_INJECTION_VARIANTS = new Set(['error-memory', 'mistake_md']);
7
+ const LATEST_ONLY_INJECTION_VARIANTS = new Set([
8
+ 'action_style',
9
+ 'error-memory',
10
+ 'mistake_md',
11
+ 'tool-awareness',
12
+ ]);
13
+ const LATEST_ONLY_INJECTION_FAMILIES = new Map([
14
+ ['swarm_mode', 'swarm-mode-state'],
15
+ ['swarm_mode_exit', 'swarm-mode-state'],
16
+ ]);
17
+
18
+ function latestOnlyInjectionFamily(variant) {
19
+ if (LATEST_ONLY_INJECTION_VARIANTS.has(variant)) return `variant:${variant}`;
20
+ return LATEST_ONLY_INJECTION_FAMILIES.get(variant) ?? null;
21
+ }
8
22
 
9
23
  function repeatedInjectionKey(message) {
10
24
  if (message?.role !== 'user') return null;
@@ -21,6 +35,7 @@ function repeatedInjectionKey(message) {
21
35
  function dedupeRepeatedInjections(history) {
22
36
  if (!Array.isArray(history) || history.length < 2) return history;
23
37
  const seenByVariant = new Map();
38
+ const seenLatestOnlyFamilies = new Set();
24
39
  const kept = [];
25
40
 
26
41
  for (let index = history.length - 1; index >= 0; index -= 1) {
@@ -30,7 +45,11 @@ function dedupeRepeatedInjections(history) {
30
45
  kept.push(message);
31
46
  continue;
32
47
  }
33
- if (LATEST_ONLY_INJECTION_VARIANTS.has(key.variant) && seenByVariant.has(key.variant)) continue;
48
+ const latestOnlyFamily = latestOnlyInjectionFamily(key.variant);
49
+ if (latestOnlyFamily !== null) {
50
+ if (seenLatestOnlyFamilies.has(latestOnlyFamily)) continue;
51
+ seenLatestOnlyFamilies.add(latestOnlyFamily);
52
+ }
34
53
  let seenTexts = seenByVariant.get(key.variant);
35
54
  if (seenTexts === undefined) {
36
55
  seenTexts = new Set();
package/blun.mjs CHANGED
@@ -260895,7 +260895,7 @@ function renderPersistedAssistantMessage(text, outputPath) {
260895
260895
  createAssistantMessagePreview(text)
260896
260896
  ].join("\n");
260897
260897
  }
260898
- var ASSISTANT_MESSAGE_MAX_CHARS, ASSISTANT_MESSAGE_OFFLOAD_MARKER, ASSISTANT_TOOL_NARRATION_MARKER, shouldOffloadHistoricalAssistantMessage, shouldCompactHistoricalAssistantToolNarration, compactHistoricalPostTelegramReplyNarration, removeSyntheticToolArgumentFailures, createAssistantMessagePreview;
260898
+ var ASSISTANT_MESSAGE_MAX_CHARS, ASSISTANT_MESSAGE_OFFLOAD_MARKER, ASSISTANT_TOOL_NARRATION_MARKER, shouldOffloadHistoricalAssistantMessage, shouldCompactHistoricalAssistantToolNarration, compactHistoricalPostTelegramReplyNarration, compactHistoricalCompletedSubagentPrompts, removeSyntheticToolArgumentFailures, createAssistantMessagePreview;
260899
260899
  var init_assistant_message_offload = __esmMin((() => {
260900
260900
  const policy = createRequire(import.meta.url)("./bin/assistant-message-offload-policy.cjs");
260901
260901
  ASSISTANT_MESSAGE_MAX_CHARS = policy.ASSISTANT_MESSAGE_MAX_CHARS;
@@ -260904,6 +260904,7 @@ var init_assistant_message_offload = __esmMin((() => {
260904
260904
  shouldOffloadHistoricalAssistantMessage = policy.shouldOffloadHistoricalAssistantMessage;
260905
260905
  shouldCompactHistoricalAssistantToolNarration = policy.shouldCompactHistoricalAssistantToolNarration;
260906
260906
  compactHistoricalPostTelegramReplyNarration = policy.compactHistoricalPostTelegramReplyNarration;
260907
+ compactHistoricalCompletedSubagentPrompts = policy.compactHistoricalCompletedSubagentPrompts;
260907
260908
  removeSyntheticToolArgumentFailures = policy.removeSyntheticToolArgumentFailures;
260908
260909
  createAssistantMessagePreview = policy.createAssistantMessagePreview;
260909
260910
  }));
@@ -260991,7 +260992,8 @@ var AssistantMessageOffload = class {
260991
260992
  return { ...message, content: replacement.content };
260992
260993
  });
260993
260994
  const narrationProjected = compactHistoricalPostTelegramReplyNarration(changed ? projected : messages);
260994
- return removeSyntheticToolArgumentFailures(narrationProjected);
260995
+ const subagentProjected = compactHistoricalCompletedSubagentPrompts(narrationProjected);
260996
+ return removeSyntheticToolArgumentFailures(subagentProjected);
260995
260997
  }
260996
260998
  reset(history = this.agent.context?.history ?? []) {
260997
260999
  const activeHashes = new Set(history.map((message) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.234",
3
+ "version": "9.1.236",
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": {