blun-king-cli 9.1.199 → 9.1.201

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,34 @@
1
+ 'use strict';
2
+
3
+ function finiteNonNegative(value) {
4
+ return Number.isFinite(value) ? Math.max(0, value) : 0;
5
+ }
6
+
7
+ function buildContextInsight(input = {}) {
8
+ const projectedTokens = finiteNonNegative(input.projectedTokenCount);
9
+ const maxTokens = finiteNonNegative(input.effectiveMaxContextTokens);
10
+ const conversationTokens = finiteNonNegative(input.conversationTokens);
11
+ const toolSchemaTokens = finiteNonNegative(input.toolSchemaTokens);
12
+ const compactionBudgetTokens = Math.min(
13
+ maxTokens,
14
+ finiteNonNegative(input.compactionBudgetTokens),
15
+ );
16
+ const freeTokens = Math.max(0, maxTokens - projectedTokens);
17
+ const ratio = maxTokens > 0
18
+ ? Math.min(1, projectedTokens / maxTokens)
19
+ : 0;
20
+
21
+ return {
22
+ projectedTokens,
23
+ maxTokens,
24
+ conversationTokens,
25
+ toolSchemaTokens,
26
+ compactionBudgetTokens,
27
+ freeTokens,
28
+ ratio,
29
+ };
30
+ }
31
+
32
+ module.exports = {
33
+ buildContextInsight,
34
+ };
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ const ERROR_MEMORY_MAX_CHARS = 2_800;
4
+
5
+ function buildCompactErrorMemoryReminder(patterns) {
6
+ const lines = [
7
+ '<error-memory-check>',
8
+ 'Vor Abschluss jede Regel pruefen; Verletzungen korrigieren oder offen benennen.',
9
+ ];
10
+
11
+ for (const pattern of patterns) {
12
+ const check = pattern.check ? ` | Pruefung: ${pattern.check}` : '';
13
+ lines.push(`${pattern.number}. ${pattern.rule}${check}`);
14
+ }
15
+
16
+ lines.push(
17
+ 'Arbeitsweise: 3-7 sichtbare Schritte; Werkzeuge proaktiv; nach zwei gleichen Fehlern Ansatz wechseln; Schritte erst nach echtem Nachweis abschliessen; nach Zielerreichung stoppen; Teilerfolg oder Scheitern mit Grund und naechstem Schritt offen melden.',
18
+ '</error-memory-check>',
19
+ );
20
+ return lines.join('\n');
21
+ }
22
+
23
+ function compactLegacyErrorMemoryReminder(text) {
24
+ const source = String(text);
25
+ if (!source.includes('<error-memory-check>') || !source.includes(' Regel: ')) return source;
26
+
27
+ const lines = source.split(/\r?\n/u);
28
+ const patterns = [];
29
+ for (let index = 0; index + 1 < lines.length; index += 1) {
30
+ const title = lines[index].match(/^\s*(\d+)\.\s+(.+)$/u);
31
+ const rule = lines[index + 1].match(/^\s*Regel:\s*(.+)$/u);
32
+ if (!title || !rule) continue;
33
+ const check = lines[index + 2]?.match(/^\s*Pruefung:\s*(.+)$/u);
34
+ patterns.push({
35
+ number: Number(title[1]),
36
+ title: title[2],
37
+ rule: rule[1],
38
+ check: check?.[1],
39
+ });
40
+ }
41
+ return patterns.length > 0 ? buildCompactErrorMemoryReminder(patterns) : source;
42
+ }
43
+
44
+ module.exports = {
45
+ ERROR_MEMORY_MAX_CHARS,
46
+ buildCompactErrorMemoryReminder,
47
+ compactLegacyErrorMemoryReminder,
48
+ };
@@ -1,6 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const LATEST_ONLY_INJECTION_VARIANTS = new Set(['mistake_md']);
3
+ const {
4
+ compactLegacyErrorMemoryReminder,
5
+ } = require('./error-memory-performance-policy.cjs');
6
+
7
+ const LATEST_ONLY_INJECTION_VARIANTS = new Set(['error-memory', 'mistake_md']);
4
8
 
5
9
  function repeatedInjectionKey(message) {
6
10
  if (message?.role !== 'user') return null;
@@ -34,7 +38,15 @@ function dedupeRepeatedInjections(history) {
34
38
  }
35
39
  if (seenTexts.has(key.text)) continue;
36
40
  seenTexts.add(key.text);
37
- kept.push(message);
41
+ if (key.variant === 'error-memory') {
42
+ const compactText = compactLegacyErrorMemoryReminder(key.text);
43
+ kept.push(compactText === key.text ? message : {
44
+ ...message,
45
+ content: [{ ...message.content[0], text: compactText }],
46
+ });
47
+ } else {
48
+ kept.push(message);
49
+ }
38
50
  }
39
51
 
40
52
  kept.reverse();
@@ -2,6 +2,7 @@
2
2
 
3
3
  const TOOL_RESULT_MAX_CHARS = 12_000;
4
4
  const TOOL_RESULT_PREVIEW_CHARS = 2_000;
5
+ const TOOL_RESULT_RECOVERY_PAGE_LINES = 20;
5
6
  const TOOL_RESULT_OFFLOAD_MARKER = '[Tool result offloaded]';
6
7
  const TOOL_RESULT_BATCH_MAX_CHARS = TOOL_RESULT_MAX_CHARS;
7
8
  const TOOL_RESULT_BATCH_MIN_ITEM_CHARS = 3_000;
@@ -171,6 +172,7 @@ module.exports = {
171
172
  TOOL_RESULT_HISTORICAL_SUCCESS_MARKER,
172
173
  TOOL_RESULT_MAX_CHARS,
173
174
  TOOL_RESULT_PREVIEW_CHARS,
175
+ TOOL_RESULT_RECOVERY_PAGE_LINES,
174
176
  TOOL_RESULT_OFFLOAD_MARKER,
175
177
  TOOL_RESULT_SUCCESS_KEEP_RECENT_MESSAGES,
176
178
  compactHistoricalSuccessfulToolResults,
package/blun.mjs CHANGED
@@ -79224,6 +79224,10 @@ var init_injector = __esmMin((() => {
79224
79224
  //#endregion
79225
79225
  //#region ../../packages/agent-core/src/agent/injection/error-memory.ts
79226
79226
  function buildErrorMemoryReminder(patterns) {
79227
+ try {
79228
+ const { buildCompactErrorMemoryReminder } = createRequire(import.meta.url)("./bin/error-memory-performance-policy.cjs");
79229
+ return buildCompactErrorMemoryReminder(patterns);
79230
+ } catch {}
79227
79231
  const lines = [];
79228
79232
  lines.push("<error-memory-check>");
79229
79233
  lines.push("");
@@ -260377,7 +260381,7 @@ function renderPersistedToolResult(toolName, toolCallId, text, outputPath, toolT
260377
260381
  `output_size_chars: ${String(text.length)}`,
260378
260382
  `output_size_bytes: ${String(Buffer.byteLength(text, "utf8"))}`,
260379
260383
  `output_path: ${outputPath}`,
260380
- "next_step: Use Read with output_path to page through the full output."
260384
+ `next_step: Use Read with output_path using n_lines <= ${String(TOOL_RESULT_RECOVERY_PAGE_LINES)}; advance line_offset between calls.`
260381
260385
  ];
260382
260386
  lines.push("", "[preview: head and tail]", createToolResultPreview(text));
260383
260387
  return lines.join("\n");
@@ -260392,7 +260396,7 @@ function renderReadSourceReference(toolName, toolCallId, text, outputPath) {
260392
260396
  `output_size_chars: ${String(text.length)}`,
260393
260397
  `output_size_bytes: ${String(Buffer.byteLength(text, "utf8"))}`,
260394
260398
  `output_path: ${outputPath}`,
260395
- "next_step: Use Read with output_path to page through the source file."
260399
+ `next_step: Use Read with output_path using n_lines <= ${String(TOOL_RESULT_RECOVERY_PAGE_LINES)}; advance line_offset between calls.`
260396
260400
  ];
260397
260401
  lines.push("", "[preview: head and tail]", createToolResultPreview(text));
260398
260402
  return lines.join("\n");
@@ -260437,19 +260441,20 @@ function renderHistoricalToolResultReference(toolName, toolCallId, text, outputP
260437
260441
  `output_size_chars: ${String(text.length)}`,
260438
260442
  `output_size_bytes: ${String(Buffer.byteLength(text, "utf8"))}`,
260439
260443
  `output_path: ${outputPath}`,
260440
- "next_step: Use Read with output_path if the full result is needed again."
260444
+ `next_step: Use Read with output_path using n_lines <= ${String(TOOL_RESULT_RECOVERY_PAGE_LINES)}; advance line_offset between calls.`
260441
260445
  ].join("\n");
260442
260446
  }
260443
260447
  function safeToolResultFileStem(toolName, toolCallId) {
260444
260448
  return `${toolName}-${toolCallId}`.replace(/[^a-zA-Z0-9._-]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 80) || "tool-result";
260445
260449
  }
260446
- var TOOL_RESULT_MAX_CHARS, TOOL_RESULT_PREVIEW_CHARS, TOOL_RESULT_OFFLOAD_MARKER, TOOL_RESULT_HISTORICAL_KEEP_RECENT_MESSAGES, shouldOffloadToolResult, createToolResultPreview, compactPersistedToolResultReference, compactHistoricalSuccessfulToolResults, selectToolResultBatchOffloads, selectHistoricalToolResultOffloads, buildToolResultOffloadTelemetry;
260450
+ var TOOL_RESULT_MAX_CHARS, TOOL_RESULT_PREVIEW_CHARS, TOOL_RESULT_RECOVERY_PAGE_LINES, TOOL_RESULT_OFFLOAD_MARKER, TOOL_RESULT_HISTORICAL_KEEP_RECENT_MESSAGES, shouldOffloadToolResult, createToolResultPreview, compactPersistedToolResultReference, compactHistoricalSuccessfulToolResults, selectToolResultBatchOffloads, selectHistoricalToolResultOffloads, buildToolResultOffloadTelemetry;
260447
260451
  var init_tool_result_budget = __esmMin((() => {
260448
260452
  init_dist$6();
260449
260453
  const toolResultOffloadPolicy = createRequire(import.meta.url)("./bin/tool-result-offload-policy.cjs");
260450
260454
  ({ buildToolResultOffloadTelemetry } = createRequire(import.meta.url)("./bin/tool-result-offload-telemetry.cjs"));
260451
260455
  TOOL_RESULT_MAX_CHARS = toolResultOffloadPolicy.TOOL_RESULT_MAX_CHARS;
260452
260456
  TOOL_RESULT_PREVIEW_CHARS = toolResultOffloadPolicy.TOOL_RESULT_PREVIEW_CHARS;
260457
+ TOOL_RESULT_RECOVERY_PAGE_LINES = toolResultOffloadPolicy.TOOL_RESULT_RECOVERY_PAGE_LINES;
260453
260458
  TOOL_RESULT_OFFLOAD_MARKER = toolResultOffloadPolicy.TOOL_RESULT_OFFLOAD_MARKER;
260454
260459
  TOOL_RESULT_HISTORICAL_KEEP_RECENT_MESSAGES = toolResultOffloadPolicy.TOOL_RESULT_HISTORICAL_KEEP_RECENT_MESSAGES;
260455
260460
  shouldOffloadToolResult = toolResultOffloadPolicy.shouldOffloadToolResult;
@@ -403025,11 +403030,18 @@ const BUILTIN_SLASH_COMMAND_DEFINITIONS = [
403025
403030
  },
403026
403031
  {
403027
403032
  name: "usage",
403028
- aliases: ["context"],
403033
+ aliases: [],
403029
403034
  descriptionKey: "command.usage.description",
403030
403035
  priority: 60,
403031
403036
  availability: "always"
403032
403037
  },
403038
+ {
403039
+ name: "context",
403040
+ aliases: [],
403041
+ descriptionKey: "usage.context.title",
403042
+ priority: 65,
403043
+ availability: "always"
403044
+ },
403033
403045
  {
403034
403046
  name: "status",
403035
403047
  aliases: [],
@@ -416768,6 +416780,7 @@ function buildManagedUsageReportLines(options) {
416768
416780
  }
416769
416781
  var { buildApprovalRejectionStop } = createRequire(import.meta.url)("./bin/approval-rejection-stop.cjs");
416770
416782
  var { reconcileContextBudget } = createRequire(import.meta.url)("./bin/context-budget-ledger.cjs");
416783
+ var { buildContextInsight } = createRequire(import.meta.url)("./bin/context-insight-policy.cjs");
416771
416784
  function buildUsageReportLines(options) {
416772
416785
  const accent = (text) => currentTheme.boldFg("primary", text);
416773
416786
  const value = (text) => currentTheme.fg("text", text);
@@ -417812,6 +417825,29 @@ function managedUsageErrorCode(error) {
417812
417825
  }
417813
417826
  return record.status === 401 || record.status === 403 ? "unauthenticated" : "unavailable";
417814
417827
  }
417828
+ function buildContextInsightLines(insight) {
417829
+ const value = (text) => currentTheme.fg("text", text);
417830
+ const muted = (text) => currentTheme.fg("textDim", text);
417831
+ const severityColor = (ratio) => ratio >= 0.9 ? "error" : ratio >= 0.75 ? "warning" : "success";
417832
+ const locale = getCurrentUiLocale();
417833
+ const bar = renderProgressBar(insight.ratio, 20);
417834
+ const barColoured = currentTheme.fg(severityColor(insight.ratio), bar);
417835
+ const percentage = `${(insight.ratio * 100).toFixed(1)}%`;
417836
+ const lines = [
417837
+ ` ${barColoured} ${value(percentage.padStart(6, " "))} ${muted(`(${formatExactTokenCount(insight.projectedTokens, locale)} / ${formatExactTokenCount(insight.maxTokens, locale)})`)}`,
417838
+ ` ${muted(`${uiText("export.conversation")}:`)} ${value(formatExactTokenCount(insight.conversationTokens, locale))}`,
417839
+ ` ${muted(`${uiText("mcp.capability.tools")}:`)} ${value(formatExactTokenCount(insight.toolSchemaTokens, locale))}`,
417840
+ ` ${muted(`${uiText("command.compact.description")}:`)} ${value(formatExactTokenCount(insight.compactionBudgetTokens, locale))}`,
417841
+ ` ${muted(uiText("usage.plan.metric.remaining", { count: formatExactTokenCount(insight.freeTokens, locale) }))}`
417842
+ ];
417843
+ return lines;
417844
+ }
417845
+ async function showContextInsight(host) {
417846
+ const insight = buildContextInsight(await host.requireSession().getContext());
417847
+ const panel = new UsagePanelComponent(() => buildContextInsightLines(insight), "primary", uiText("usage.context.title"));
417848
+ host.state.transcriptContainer.addChild(panel);
417849
+ host.state.ui.requestRender();
417850
+ }
417815
417851
  async function showUsage(host) {
417816
417852
  const [sessionUsage, managedUsage, runtimeStatus] = await Promise.all([
417817
417853
  loadSessionUsageReport(host),
@@ -495021,6 +495057,9 @@ async function handleBuiltInSlashCommand(host, name, args) {
495021
495057
  case "premortem":
495022
495058
  await handlePremortemCommand(host, args);
495023
495059
  return;
495060
+ case "context":
495061
+ await showContextInsight(host);
495062
+ return;
495024
495063
  case "usage":
495025
495064
  await showUsage(host);
495026
495065
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.199",
3
+ "version": "9.1.201",
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": {