blun-king-cli 9.1.218 → 9.1.220

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.
@@ -10,6 +10,7 @@ const INTRA_MESSAGE_MIN_BLOCK_CHARS = 40;
10
10
  const INTRA_MESSAGE_MIN_SAVED_CHARS = 1_000;
11
11
  const INTRA_MESSAGE_SIMILARITY_THRESHOLD = 0.88;
12
12
  const INTRA_MESSAGE_REPEAT_PLACEHOLDER = '[Exact repeated assistant paragraphs omitted from model projection; raw history preserved.]';
13
+ const intraMessageProjectionCache = new WeakMap();
13
14
 
14
15
  function isUserPrompt(message) {
15
16
  if (message?.role !== 'user') return false;
@@ -132,8 +133,24 @@ function compactRepeatedAssistantParagraphs(message) {
132
133
  )) return null;
133
134
 
134
135
  const text = textParts[0].text;
136
+ const cached = intraMessageProjectionCache.get(message);
137
+ if (
138
+ cached?.content === message.content
139
+ && cached.textPart === textParts[0]
140
+ && cached.text === text
141
+ ) return cached.projected;
142
+
143
+ const cacheProjection = (projected) => {
144
+ intraMessageProjectionCache.set(message, {
145
+ content: message.content,
146
+ projected,
147
+ text,
148
+ textPart: textParts[0],
149
+ });
150
+ return projected;
151
+ };
135
152
  const blocks = text.split(/\n\s*\n/u).map((block) => block.trim()).filter(Boolean);
136
- if (blocks.length < INTRA_MESSAGE_MIN_REPEATS + 1) return null;
153
+ if (blocks.length < INTRA_MESSAGE_MIN_REPEATS + 1) return cacheProjection(null);
137
154
  const protectedIndexes = fencedBlockIndexes(blocks);
138
155
 
139
156
  const clusters = [];
@@ -150,7 +167,7 @@ function compactRepeatedAssistantParagraphs(message) {
150
167
  const repeatedIndexes = new Set(clusters
151
168
  .filter((cluster) => cluster.indexes.length >= INTRA_MESSAGE_MIN_REPEATS)
152
169
  .flatMap((cluster) => cluster.indexes.slice(1)));
153
- if (repeatedIndexes.size === 0) return null;
170
+ if (repeatedIndexes.size === 0) return cacheProjection(null);
154
171
 
155
172
  const projectedBlocks = [];
156
173
  let markerAdded = false;
@@ -166,13 +183,13 @@ function compactRepeatedAssistantParagraphs(message) {
166
183
  }
167
184
 
168
185
  const projectedText = projectedBlocks.join('\n\n');
169
- if (text.length - projectedText.length < INTRA_MESSAGE_MIN_SAVED_CHARS) return null;
170
- return {
186
+ if (text.length - projectedText.length < INTRA_MESSAGE_MIN_SAVED_CHARS) return cacheProjection(null);
187
+ return cacheProjection({
171
188
  ...message,
172
189
  content: message.content.map((part) => (
173
190
  part === textParts[0] ? { ...part, text: projectedText } : part
174
191
  )),
175
- };
192
+ });
176
193
  }
177
194
 
178
195
  function projectRepeatedAssistantResponses(history) {
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ isLowInformationPersonalMemoryQuery,
5
+ } = require('./personal-memory-performance-policy.cjs');
6
+
7
+ function isRealUserMessage(message) {
8
+ if (message?.role !== 'user') return false;
9
+ const kind = message.origin?.kind;
10
+ return kind !== 'injection' && kind !== 'compaction_summary' && kind !== 'system_trigger';
11
+ }
12
+
13
+ function textFromMessage(message) {
14
+ if (typeof message?.content === 'string') return message.content.trim();
15
+ if (!Array.isArray(message?.content)) return '';
16
+ return message.content
17
+ .filter((part) => part?.type === 'text' && typeof part.text === 'string')
18
+ .map((part) => part.text.trim())
19
+ .filter(Boolean)
20
+ .join('\n');
21
+ }
22
+
23
+ function directMessageText(value) {
24
+ let text = value.trim();
25
+ const marker = /^#?\s*\[tg\s+dm\b[^\]]*\]\s*/iu;
26
+ if (!marker.test(text)) return text;
27
+ text = text.replace(marker, '');
28
+ text = text.replace(/^[^\r\n]{1,160}\s+schrieb:\s*/iu, '');
29
+ return text.replace(/\r?\nWeiter-Signal:\s*[\s\S]*$/iu, '').trim();
30
+ }
31
+
32
+ function hasToolActivityAfter(history, userIndex) {
33
+ return history.slice(userIndex + 1).some((message) => (
34
+ message?.role === 'tool'
35
+ || (message?.role === 'assistant'
36
+ && (Array.isArray(message.toolCalls) || Array.isArray(message.tool_calls))
37
+ && (message.toolCalls?.length > 0 || message.tool_calls?.length > 0))
38
+ ));
39
+ }
40
+
41
+ function shouldSyncValidatedLearningCandidate(history) {
42
+ if (!Array.isArray(history)) return true;
43
+ const userIndex = history.findLastIndex(isRealUserMessage);
44
+ if (userIndex < 0 || hasToolActivityAfter(history, userIndex)) return true;
45
+ const message = history[userIndex];
46
+ if (Array.isArray(message.content)) {
47
+ const hasAttachment = message.content.some((part) => part?.type !== 'text' && part?.type !== 'think');
48
+ if (hasAttachment) return true;
49
+ }
50
+ return !isLowInformationPersonalMemoryQuery(directMessageText(textFromMessage(message)));
51
+ }
52
+
53
+ module.exports = { shouldSyncValidatedLearningCandidate };
package/blun.mjs CHANGED
@@ -232151,18 +232151,20 @@ function buildValidatedLearningSignalReminder(signal) {
232151
232151
  lines.push("</validated-learning-signal>");
232152
232152
  return lines.join("\n");
232153
232153
  }
232154
- var ValidatedLearningSignalInjector, syncValidatedLearningCandidate;
232154
+ var ValidatedLearningSignalInjector, shouldSyncValidatedLearningCandidate, syncValidatedLearningCandidate;
232155
232155
  var init_validated_learning_signal = __esmMin((() => {
232156
232156
  init_injector();
232157
232157
  ({ syncValidatedLearningCandidate } = createRequire(import.meta.url)("./bin/validated-learning-signal.cjs"));
232158
+ ({ shouldSyncValidatedLearningCandidate } = createRequire(import.meta.url)("./bin/validated-learning-performance-policy.cjs"));
232158
232159
  ValidatedLearningSignalInjector = class extends DynamicInjector {
232159
232160
  injectionVariant = "validated_learning_signal";
232160
232161
  async inject() {
232162
+ const existing = this.agent.context.history.filter(isValidatedLearningSignalReminder);
232163
+ if (!shouldSyncValidatedLearningCandidate(this.agent.context.history)) return;
232161
232164
  const signal = syncValidatedLearningCandidate(this.agent.context.history, {
232162
232165
  homeDir: process.env["BLUN_SHARED_HOME"] ?? process.env["BLUN_HOME"] ?? "",
232163
232166
  profile: process.env["BLUN_PROFILE"] ?? "default"
232164
232167
  });
232165
- const existing = this.agent.context.history.filter(isValidatedLearningSignalReminder);
232166
232168
  if (signal === null) {
232167
232169
  if (existing.length > 0) this.agent.context.removeSystemRemindersMatching(isValidatedLearningSignalReminder);
232168
232170
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.218",
3
+ "version": "9.1.220",
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": {