blun-king-cli 9.1.202 → 9.1.204

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.
@@ -1,6 +1,69 @@
1
1
  'use strict';
2
2
 
3
3
  const ERROR_MEMORY_MAX_CHARS = 2_800;
4
+ const ERROR_MEMORY_MAX_PATTERNS = 6;
5
+ const CORE_PATTERN_NUMBERS = new Set([4, 9, 10, 11]);
6
+ const STOP_WORDS = new Set([
7
+ 'aber', 'alle', 'alles', 'auch', 'belegt', 'beweis', 'echt', 'echte', 'echten',
8
+ 'echter', 'eine', 'einem', 'einen', 'einer', 'das', 'den', 'fuer', 'gegen',
9
+ 'haben', 'hier', 'immer',
10
+ 'jetzt', 'kann', 'machen', 'mehr', 'nicht', 'noch', 'oder', 'pruefe', 'pruefen',
11
+ 'pruefung', 'sein', 'sind', 'soll', 'und', 'vollstaendig', 'vollstaendige',
12
+ 'wenn', 'werden', 'with', 'that',
13
+ 'this', 'from', 'have', 'into', 'your', 'you', 'the', 'and', 'for', 'are',
14
+ ]);
15
+
16
+ function normalizedTerms(value) {
17
+ return [...new Set(String(value || '')
18
+ .normalize('NFKD')
19
+ .replace(/\p{M}/gu, '')
20
+ .toLowerCase()
21
+ .match(/[\p{L}\p{N}_-]{3,}/gu) || [])]
22
+ .filter((term) => !STOP_WORDS.has(term));
23
+ }
24
+
25
+ function fieldMatchesTerm(fieldTerms, term) {
26
+ return fieldTerms.some((fieldTerm) => (
27
+ fieldTerm === term
28
+ || (term.length >= 6 && fieldTerm.includes(term))
29
+ || (fieldTerm.length >= 6 && term.includes(fieldTerm))
30
+ ));
31
+ }
32
+
33
+ function selectRelevantErrorMemoryPatterns(patterns, query, options = {}) {
34
+ const maxPatterns = Math.max(1, Number(options.maxPatterns) || ERROR_MEMORY_MAX_PATTERNS);
35
+ const source = Array.isArray(patterns) ? patterns.filter(Boolean) : [];
36
+ if (source.length <= maxPatterns) return source;
37
+
38
+ const queryTerms = normalizedTerms(query);
39
+ const ranked = source.map((pattern, index) => {
40
+ const title = normalizedTerms(pattern.title);
41
+ const rule = normalizedTerms(pattern.rule);
42
+ const check = normalizedTerms(pattern.check);
43
+ let score = 0;
44
+ for (const term of queryTerms) {
45
+ if (fieldMatchesTerm(title, term)) score += 4;
46
+ if (fieldMatchesTerm(rule, term)) score += 2;
47
+ if (fieldMatchesTerm(check, term)) score += 1;
48
+ }
49
+ return { index, pattern, score };
50
+ });
51
+ const selectedIndexes = new Set(ranked
52
+ .filter(({ pattern }) => CORE_PATTERN_NUMBERS.has(Number(pattern.number)))
53
+ .map(({ index }) => index));
54
+ ranked
55
+ .filter(({ index, score }) => !selectedIndexes.has(index) && score > 0)
56
+ .sort((left, right) => right.score - left.score || left.index - right.index)
57
+ .slice(0, Math.max(0, maxPatterns - selectedIndexes.size))
58
+ .forEach(({ index }) => selectedIndexes.add(index));
59
+
60
+ if (selectedIndexes.size === 0) {
61
+ source.slice(-Math.min(2, maxPatterns)).forEach((pattern) => {
62
+ selectedIndexes.add(source.indexOf(pattern));
63
+ });
64
+ }
65
+ return source.filter((pattern, index) => selectedIndexes.has(index)).slice(0, maxPatterns);
66
+ }
4
67
 
5
68
  function buildCompactErrorMemoryReminder(patterns) {
6
69
  const lines = [
@@ -42,7 +105,9 @@ function compactLegacyErrorMemoryReminder(text) {
42
105
  }
43
106
 
44
107
  module.exports = {
108
+ ERROR_MEMORY_MAX_PATTERNS,
45
109
  ERROR_MEMORY_MAX_CHARS,
46
110
  buildCompactErrorMemoryReminder,
47
111
  compactLegacyErrorMemoryReminder,
112
+ selectRelevantErrorMemoryPatterns,
48
113
  };
@@ -237,8 +237,11 @@ function createDeferredToolLoader(selectedTools, deferredTools, loadedToolNames
237
237
  };
238
238
  }
239
239
  return {
240
- isError: true,
241
- output: `No deferred tools matched: ${query || '[empty query]'}`,
240
+ isError: false,
241
+ output: [
242
+ `No eligible deferred tool is available for: ${query || '[empty query]'}.`,
243
+ 'Do not retry ToolSearch with synonyms; use a loaded alternative or report the integration as unavailable.',
244
+ ].join(' '),
242
245
  };
243
246
  }
244
247
  if (query.toLowerCase().startsWith('select:') && matches.length !== 1) {
package/blun.mjs CHANGED
@@ -79260,6 +79260,11 @@ var init_error_memory$1 = __esmMin((() => {
79260
79260
  getInjection() {
79261
79261
  const patterns = this.agent.errorMemory?.getActivePatterns();
79262
79262
  if (!patterns || patterns.length === 0) return void 0;
79263
+ try {
79264
+ const { buildCompactErrorMemoryReminder, selectRelevantErrorMemoryPatterns } = createRequire(import.meta.url)("./bin/error-memory-performance-policy.cjs");
79265
+ const { recentUserText } = createRequire(import.meta.url)("./bin/mistake-relevance-policy.cjs");
79266
+ return buildCompactErrorMemoryReminder(selectRelevantErrorMemoryPatterns(patterns, recentUserText(this.agent.context.history)));
79267
+ } catch {}
79263
79268
  return buildErrorMemoryReminder(patterns);
79264
79269
  }
79265
79270
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.202",
3
+ "version": "9.1.204",
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": {