blun-king-cli 9.1.199 → 9.1.200
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.
- package/bin/context-insight-policy.cjs +34 -0
- package/bin/tool-result-offload-policy.cjs +2 -0
- package/blun.mjs +40 -5
- package/package.json +1 -1
|
@@ -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
|
+
};
|
|
@@ -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
|
@@ -260377,7 +260377,7 @@ function renderPersistedToolResult(toolName, toolCallId, text, outputPath, toolT
|
|
|
260377
260377
|
`output_size_chars: ${String(text.length)}`,
|
|
260378
260378
|
`output_size_bytes: ${String(Buffer.byteLength(text, "utf8"))}`,
|
|
260379
260379
|
`output_path: ${outputPath}`,
|
|
260380
|
-
|
|
260380
|
+
`next_step: Use Read with output_path using n_lines <= ${String(TOOL_RESULT_RECOVERY_PAGE_LINES)}; advance line_offset between calls.`
|
|
260381
260381
|
];
|
|
260382
260382
|
lines.push("", "[preview: head and tail]", createToolResultPreview(text));
|
|
260383
260383
|
return lines.join("\n");
|
|
@@ -260392,7 +260392,7 @@ function renderReadSourceReference(toolName, toolCallId, text, outputPath) {
|
|
|
260392
260392
|
`output_size_chars: ${String(text.length)}`,
|
|
260393
260393
|
`output_size_bytes: ${String(Buffer.byteLength(text, "utf8"))}`,
|
|
260394
260394
|
`output_path: ${outputPath}`,
|
|
260395
|
-
|
|
260395
|
+
`next_step: Use Read with output_path using n_lines <= ${String(TOOL_RESULT_RECOVERY_PAGE_LINES)}; advance line_offset between calls.`
|
|
260396
260396
|
];
|
|
260397
260397
|
lines.push("", "[preview: head and tail]", createToolResultPreview(text));
|
|
260398
260398
|
return lines.join("\n");
|
|
@@ -260437,19 +260437,20 @@ function renderHistoricalToolResultReference(toolName, toolCallId, text, outputP
|
|
|
260437
260437
|
`output_size_chars: ${String(text.length)}`,
|
|
260438
260438
|
`output_size_bytes: ${String(Buffer.byteLength(text, "utf8"))}`,
|
|
260439
260439
|
`output_path: ${outputPath}`,
|
|
260440
|
-
|
|
260440
|
+
`next_step: Use Read with output_path using n_lines <= ${String(TOOL_RESULT_RECOVERY_PAGE_LINES)}; advance line_offset between calls.`
|
|
260441
260441
|
].join("\n");
|
|
260442
260442
|
}
|
|
260443
260443
|
function safeToolResultFileStem(toolName, toolCallId) {
|
|
260444
260444
|
return `${toolName}-${toolCallId}`.replace(/[^a-zA-Z0-9._-]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 80) || "tool-result";
|
|
260445
260445
|
}
|
|
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;
|
|
260446
|
+
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
260447
|
var init_tool_result_budget = __esmMin((() => {
|
|
260448
260448
|
init_dist$6();
|
|
260449
260449
|
const toolResultOffloadPolicy = createRequire(import.meta.url)("./bin/tool-result-offload-policy.cjs");
|
|
260450
260450
|
({ buildToolResultOffloadTelemetry } = createRequire(import.meta.url)("./bin/tool-result-offload-telemetry.cjs"));
|
|
260451
260451
|
TOOL_RESULT_MAX_CHARS = toolResultOffloadPolicy.TOOL_RESULT_MAX_CHARS;
|
|
260452
260452
|
TOOL_RESULT_PREVIEW_CHARS = toolResultOffloadPolicy.TOOL_RESULT_PREVIEW_CHARS;
|
|
260453
|
+
TOOL_RESULT_RECOVERY_PAGE_LINES = toolResultOffloadPolicy.TOOL_RESULT_RECOVERY_PAGE_LINES;
|
|
260453
260454
|
TOOL_RESULT_OFFLOAD_MARKER = toolResultOffloadPolicy.TOOL_RESULT_OFFLOAD_MARKER;
|
|
260454
260455
|
TOOL_RESULT_HISTORICAL_KEEP_RECENT_MESSAGES = toolResultOffloadPolicy.TOOL_RESULT_HISTORICAL_KEEP_RECENT_MESSAGES;
|
|
260455
260456
|
shouldOffloadToolResult = toolResultOffloadPolicy.shouldOffloadToolResult;
|
|
@@ -403025,11 +403026,18 @@ const BUILTIN_SLASH_COMMAND_DEFINITIONS = [
|
|
|
403025
403026
|
},
|
|
403026
403027
|
{
|
|
403027
403028
|
name: "usage",
|
|
403028
|
-
aliases: [
|
|
403029
|
+
aliases: [],
|
|
403029
403030
|
descriptionKey: "command.usage.description",
|
|
403030
403031
|
priority: 60,
|
|
403031
403032
|
availability: "always"
|
|
403032
403033
|
},
|
|
403034
|
+
{
|
|
403035
|
+
name: "context",
|
|
403036
|
+
aliases: [],
|
|
403037
|
+
descriptionKey: "usage.context.title",
|
|
403038
|
+
priority: 65,
|
|
403039
|
+
availability: "always"
|
|
403040
|
+
},
|
|
403033
403041
|
{
|
|
403034
403042
|
name: "status",
|
|
403035
403043
|
aliases: [],
|
|
@@ -416768,6 +416776,7 @@ function buildManagedUsageReportLines(options) {
|
|
|
416768
416776
|
}
|
|
416769
416777
|
var { buildApprovalRejectionStop } = createRequire(import.meta.url)("./bin/approval-rejection-stop.cjs");
|
|
416770
416778
|
var { reconcileContextBudget } = createRequire(import.meta.url)("./bin/context-budget-ledger.cjs");
|
|
416779
|
+
var { buildContextInsight } = createRequire(import.meta.url)("./bin/context-insight-policy.cjs");
|
|
416771
416780
|
function buildUsageReportLines(options) {
|
|
416772
416781
|
const accent = (text) => currentTheme.boldFg("primary", text);
|
|
416773
416782
|
const value = (text) => currentTheme.fg("text", text);
|
|
@@ -417812,6 +417821,29 @@ function managedUsageErrorCode(error) {
|
|
|
417812
417821
|
}
|
|
417813
417822
|
return record.status === 401 || record.status === 403 ? "unauthenticated" : "unavailable";
|
|
417814
417823
|
}
|
|
417824
|
+
function buildContextInsightLines(insight) {
|
|
417825
|
+
const value = (text) => currentTheme.fg("text", text);
|
|
417826
|
+
const muted = (text) => currentTheme.fg("textDim", text);
|
|
417827
|
+
const severityColor = (ratio) => ratio >= 0.9 ? "error" : ratio >= 0.75 ? "warning" : "success";
|
|
417828
|
+
const locale = getCurrentUiLocale();
|
|
417829
|
+
const bar = renderProgressBar(insight.ratio, 20);
|
|
417830
|
+
const barColoured = currentTheme.fg(severityColor(insight.ratio), bar);
|
|
417831
|
+
const percentage = `${(insight.ratio * 100).toFixed(1)}%`;
|
|
417832
|
+
const lines = [
|
|
417833
|
+
` ${barColoured} ${value(percentage.padStart(6, " "))} ${muted(`(${formatExactTokenCount(insight.projectedTokens, locale)} / ${formatExactTokenCount(insight.maxTokens, locale)})`)}`,
|
|
417834
|
+
` ${muted(`${uiText("export.conversation")}:`)} ${value(formatExactTokenCount(insight.conversationTokens, locale))}`,
|
|
417835
|
+
` ${muted(`${uiText("mcp.capability.tools")}:`)} ${value(formatExactTokenCount(insight.toolSchemaTokens, locale))}`,
|
|
417836
|
+
` ${muted(`${uiText("command.compact.description")}:`)} ${value(formatExactTokenCount(insight.compactionBudgetTokens, locale))}`,
|
|
417837
|
+
` ${muted(uiText("usage.plan.metric.remaining", { count: formatExactTokenCount(insight.freeTokens, locale) }))}`
|
|
417838
|
+
];
|
|
417839
|
+
return lines;
|
|
417840
|
+
}
|
|
417841
|
+
async function showContextInsight(host) {
|
|
417842
|
+
const insight = buildContextInsight(await host.requireSession().getContext());
|
|
417843
|
+
const panel = new UsagePanelComponent(() => buildContextInsightLines(insight), "primary", uiText("usage.context.title"));
|
|
417844
|
+
host.state.transcriptContainer.addChild(panel);
|
|
417845
|
+
host.state.ui.requestRender();
|
|
417846
|
+
}
|
|
417815
417847
|
async function showUsage(host) {
|
|
417816
417848
|
const [sessionUsage, managedUsage, runtimeStatus] = await Promise.all([
|
|
417817
417849
|
loadSessionUsageReport(host),
|
|
@@ -495021,6 +495053,9 @@ async function handleBuiltInSlashCommand(host, name, args) {
|
|
|
495021
495053
|
case "premortem":
|
|
495022
495054
|
await handlePremortemCommand(host, args);
|
|
495023
495055
|
return;
|
|
495056
|
+
case "context":
|
|
495057
|
+
await showContextInsight(host);
|
|
495058
|
+
return;
|
|
495024
495059
|
case "usage":
|
|
495025
495060
|
await showUsage(host);
|
|
495026
495061
|
return;
|