blun-king-cli 9.1.442 → 9.1.444
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.
|
@@ -6,6 +6,7 @@ const {
|
|
|
6
6
|
|
|
7
7
|
const DEFAULT_MAX_CHARS = 3_000;
|
|
8
8
|
const DEFAULT_MAX_SECTIONS = 5;
|
|
9
|
+
const GOAL_MISTAKE_QUERY_MAX_CHARS = 2_000;
|
|
9
10
|
const RECENT_USER_MESSAGES = 4;
|
|
10
11
|
const NON_ACTIONABLE_USER_ORIGINS = new Set([
|
|
11
12
|
'background_task',
|
|
@@ -86,6 +87,55 @@ function recentUserText(history, limit = RECENT_USER_MESSAGES) {
|
|
|
86
87
|
.join('\n');
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
function boundedQueryValue(value, maxChars = 320) {
|
|
91
|
+
const text = String(value ?? '')
|
|
92
|
+
.replace(/[\u0000-\u001f\u007f]+/gu, ' ')
|
|
93
|
+
.replace(/\s+/gu, ' ')
|
|
94
|
+
.trim();
|
|
95
|
+
if (!text) return '';
|
|
96
|
+
return text.length <= maxChars ? text : `${text.slice(0, maxChars - 3).trimEnd()}...`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function goalMistakeQuery(goal) {
|
|
100
|
+
if (!goal || typeof goal !== 'object' || Array.isArray(goal) || goal.status !== 'active') return '';
|
|
101
|
+
const objective = boundedQueryValue(goal.objective, 512);
|
|
102
|
+
if (!objective) return '';
|
|
103
|
+
const checkpoint = goal.actionCheckpoint && typeof goal.actionCheckpoint === 'object'
|
|
104
|
+
&& !Array.isArray(goal.actionCheckpoint) ? goal.actionCheckpoint : null;
|
|
105
|
+
const frame = checkpoint?.problemFrame && typeof checkpoint.problemFrame === 'object'
|
|
106
|
+
&& !Array.isArray(checkpoint.problemFrame) ? checkpoint.problemFrame : null;
|
|
107
|
+
const lines = [`Goal: ${objective}`];
|
|
108
|
+
const add = (label, value, maxChars = 320) => {
|
|
109
|
+
const bounded = boundedQueryValue(value, maxChars);
|
|
110
|
+
if (bounded) lines.push(`${label}: ${bounded}`);
|
|
111
|
+
};
|
|
112
|
+
add('Completion criterion', goal.completionCriterion, 384);
|
|
113
|
+
add('Phase', checkpoint?.phase, 32);
|
|
114
|
+
add('Last verified', checkpoint?.lastVerified);
|
|
115
|
+
add('Next action', checkpoint?.nextAction);
|
|
116
|
+
const gaps = Array.isArray(frame?.missingKnowledge)
|
|
117
|
+
? frame.missingKnowledge.slice(0, 5).map((item) => boundedQueryValue(item, 256)).filter(Boolean)
|
|
118
|
+
: [];
|
|
119
|
+
if (gaps.length > 0) lines.push(`Missing knowledge: ${gaps.join(' | ')}`);
|
|
120
|
+
add('Selected action', frame?.selectedAction);
|
|
121
|
+
add('Selection reason', frame?.selectionReason);
|
|
122
|
+
add('Support choice', frame?.supportChoice, 256);
|
|
123
|
+
add('Risk', frame?.risk);
|
|
124
|
+
add('Expected evidence', checkpoint?.expectedEvidence, 384);
|
|
125
|
+
return lines.join('\n').slice(0, GOAL_MISTAKE_QUERY_MAX_CHARS).trimEnd();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function mistakeQueryTextForTurn(history, goal) {
|
|
129
|
+
const latestInput = Array.isArray(history) ? history.findLast(isActionableMistakeInput) : undefined;
|
|
130
|
+
const isGoalContinuation = latestInput?.origin?.kind === 'system_trigger'
|
|
131
|
+
&& latestInput.origin.name === 'goal_continuation';
|
|
132
|
+
if (isGoalContinuation) {
|
|
133
|
+
const query = goalMistakeQuery(goal);
|
|
134
|
+
if (query) return query;
|
|
135
|
+
}
|
|
136
|
+
return recentUserText(history);
|
|
137
|
+
}
|
|
138
|
+
|
|
89
139
|
function isLowInformationMistakeTurn(history) {
|
|
90
140
|
if (!Array.isArray(history)) return false;
|
|
91
141
|
const message = history.findLast(isActionableMistakeInput);
|
|
@@ -258,8 +308,10 @@ function selectRelevantMistakeContent(source, query, options = {}) {
|
|
|
258
308
|
module.exports = {
|
|
259
309
|
DEFAULT_MAX_CHARS,
|
|
260
310
|
DEFAULT_MAX_SECTIONS,
|
|
311
|
+
GOAL_MISTAKE_QUERY_MAX_CHARS,
|
|
261
312
|
RECENT_USER_MESSAGES,
|
|
262
313
|
isLowInformationMistakeTurn,
|
|
314
|
+
mistakeQueryTextForTurn,
|
|
263
315
|
recentUserText,
|
|
264
316
|
semanticSignalTags,
|
|
265
317
|
selectRelevantMistakeContent,
|
|
@@ -266,6 +266,17 @@ function rankedToolNamesForTurnText(tools, value, options = {}) {
|
|
|
266
266
|
return new Set(ranked.slice(0, maxTools).map((entry) => entry.name));
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
function rankedSupportToolNamesForGoal(tools, goal, origin) {
|
|
270
|
+
if (origin?.kind !== 'system_trigger' || origin?.name !== 'goal_continuation') return new Set();
|
|
271
|
+
if (goal?.status !== 'active') return new Set();
|
|
272
|
+
const checkpoint = goal.actionCheckpoint;
|
|
273
|
+
if (checkpoint?.phase === 'wait' || checkpoint?.nextTrigger?.kind !== 'immediate') return new Set();
|
|
274
|
+
const supportChoice = String(checkpoint?.problemFrame?.supportChoice ?? '').trim();
|
|
275
|
+
const explicitSupport = supportChoice.match(/^(?:tool|skill)\s*:\s*(.+)$/iu);
|
|
276
|
+
if (!explicitSupport?.[1]) return new Set();
|
|
277
|
+
return rankedToolNamesForTurnText(tools, supportChoice, { maxTools: 1 });
|
|
278
|
+
}
|
|
279
|
+
|
|
269
280
|
function searchRelatedDeferredTools(tools, query, options = {}) {
|
|
270
281
|
const normalized = normalizeDeferredToolQuery(query).toLowerCase();
|
|
271
282
|
if (!normalized || normalized.startsWith('select:')) return [];
|
|
@@ -452,6 +463,7 @@ module.exports = {
|
|
|
452
463
|
mediaGenerationToolNamesForText,
|
|
453
464
|
mediaToolNamesForTurnText,
|
|
454
465
|
normalizeDeferredToolQuery,
|
|
466
|
+
rankedSupportToolNamesForGoal,
|
|
455
467
|
rankedToolNamesForTurnText,
|
|
456
468
|
rememberDeferredToolAfterNotFound,
|
|
457
469
|
toolSchemaBudgetTokens,
|
package/blun.mjs
CHANGED
|
@@ -231582,11 +231582,11 @@ async function readProjectMistakeSources(agent) {
|
|
|
231582
231582
|
}
|
|
231583
231583
|
return sources;
|
|
231584
231584
|
}
|
|
231585
|
-
var MistakeMdInjector, isLowInformationMistakeTurn,
|
|
231585
|
+
var MistakeMdInjector, isLowInformationMistakeTurn, mistakeQueryTextForTurn, selectRelevantMistakeSources;
|
|
231586
231586
|
var init_mistake_md = __esmMin((() => {
|
|
231587
231587
|
init_injector();
|
|
231588
231588
|
init_mistake_md_writer();
|
|
231589
|
-
({ isLowInformationMistakeTurn,
|
|
231589
|
+
({ isLowInformationMistakeTurn, mistakeQueryTextForTurn, selectRelevantMistakeSources } = createRequire(import.meta.url)("./bin/mistake-relevance-policy.cjs"));
|
|
231590
231590
|
MistakeMdInjector = class extends DynamicInjector {
|
|
231591
231591
|
injectionVariant = "mistake_md";
|
|
231592
231592
|
reserveChecked = false;
|
|
@@ -231635,7 +231635,7 @@ var init_mistake_md = __esmMin((() => {
|
|
|
231635
231635
|
content: sharedContent
|
|
231636
231636
|
});
|
|
231637
231637
|
if (sources.length === 0) return void 0;
|
|
231638
|
-
const query =
|
|
231638
|
+
const query = mistakeQueryTextForTurn(this.agent.context.history, this.agent.goal.getGoal().goal);
|
|
231639
231639
|
const selected = selectRelevantMistakeSources(sources, query);
|
|
231640
231640
|
if (!selected.text) return void 0;
|
|
231641
231641
|
let prefix = "";
|
|
@@ -261646,7 +261646,7 @@ function toolResultText(result) {
|
|
|
261646
261646
|
function abandonedToolResultOutput(ended) {
|
|
261647
261647
|
return `Tool call did not complete: ${ended.reason === "cancelled" ? "the turn was cancelled" : ended.reason === "failed" ? `the turn failed${ended.error !== void 0 ? ` (${ended.error.message})` : ""}` : "the turn ended"} before its result was recorded. Do not assume the tool completed successfully.`;
|
|
261648
261648
|
}
|
|
261649
|
-
var BLUN_CORE_TOOL_NAMES, BLUN_LEAN_TOOL_NAMES, BLUN_ATTACHMENT_MARKER_RE, BLUN_TELEGRAM_OUTBOUND_TOOL_RE, BLUN_TELEGRAM_CHANNEL_RE, BLUN_TOOL_BUDGET_RATIO, createDeferredToolLoader, mediaToolNamesForTurnText, rankedToolNamesForTurnText, rememberDeferredToolAfterNotFound, toolSchemaBudgetTokens, projectRecurringCronHistory, TelegramDeliveryLedger, createRuntimeCognitiveTurnLifecycle, cognitiveFocusScopesForTurn, buildCognitiveWorkFocus, buildAttentionQueueItem, LLM_NOT_SET_MESSAGE, GOAL_CONTINUATION_ORIGIN, GOAL_COMPLETION_REMINDER_NAME, GOAL_BLOCKED_REMINDER_NAME, GOAL_RATE_LIMIT_PAUSE_REASON, GOAL_PROVIDER_CONNECTION_PAUSE_PREFIX, GOAL_PROVIDER_AUTH_PAUSE_PREFIX, GOAL_PROVIDER_API_PAUSE_PREFIX, GOAL_MODEL_CONFIG_PAUSE_PREFIX, GOAL_RUNTIME_PAUSE_PREFIX, GOAL_PROVIDER_FILTERED_PAUSE_REASON, GOAL_CONTINUATION_PROMPT, TurnFlow;
|
|
261649
|
+
var BLUN_CORE_TOOL_NAMES, BLUN_LEAN_TOOL_NAMES, BLUN_ATTACHMENT_MARKER_RE, BLUN_TELEGRAM_OUTBOUND_TOOL_RE, BLUN_TELEGRAM_CHANNEL_RE, BLUN_TOOL_BUDGET_RATIO, createDeferredToolLoader, mediaToolNamesForTurnText, rankedSupportToolNamesForGoal, rankedToolNamesForTurnText, rememberDeferredToolAfterNotFound, toolSchemaBudgetTokens, projectRecurringCronHistory, TelegramDeliveryLedger, createRuntimeCognitiveTurnLifecycle, cognitiveFocusScopesForTurn, buildCognitiveWorkFocus, buildAttentionQueueItem, LLM_NOT_SET_MESSAGE, GOAL_CONTINUATION_ORIGIN, GOAL_COMPLETION_REMINDER_NAME, GOAL_BLOCKED_REMINDER_NAME, GOAL_RATE_LIMIT_PAUSE_REASON, GOAL_PROVIDER_CONNECTION_PAUSE_PREFIX, GOAL_PROVIDER_AUTH_PAUSE_PREFIX, GOAL_PROVIDER_API_PAUSE_PREFIX, GOAL_MODEL_CONFIG_PAUSE_PREFIX, GOAL_RUNTIME_PAUSE_PREFIX, GOAL_PROVIDER_FILTERED_PAUSE_REASON, GOAL_CONTINUATION_PROMPT, TurnFlow;
|
|
261650
261650
|
var init_turn = __esmMin((() => {
|
|
261651
261651
|
init_dist$4();
|
|
261652
261652
|
init_src$4();
|
|
@@ -261663,7 +261663,7 @@ var init_turn = __esmMin((() => {
|
|
|
261663
261663
|
init_tool_result_budget();
|
|
261664
261664
|
init_user_message_offload();
|
|
261665
261665
|
init_assistant_message_offload();
|
|
261666
|
-
({ CORE_TOOL_NAMES: BLUN_CORE_TOOL_NAMES, createDeferredToolLoader, mediaToolNamesForTurnText, rankedToolNamesForTurnText, rememberDeferredToolAfterNotFound, toolSchemaBudgetTokens } = createRequire(import.meta.url)("./bin/turn-tool-performance-policy.cjs"));
|
|
261666
|
+
({ CORE_TOOL_NAMES: BLUN_CORE_TOOL_NAMES, createDeferredToolLoader, mediaToolNamesForTurnText, rankedSupportToolNamesForGoal, rankedToolNamesForTurnText, rememberDeferredToolAfterNotFound, toolSchemaBudgetTokens } = createRequire(import.meta.url)("./bin/turn-tool-performance-policy.cjs"));
|
|
261667
261667
|
({ projectRecurringCronHistory } = createRequire(import.meta.url)("./bin/recurring-cron-history-policy.cjs"));
|
|
261668
261668
|
({ TelegramDeliveryLedger } = createRequire(import.meta.url)("./bin/repeated-user-message-projection.cjs"));
|
|
261669
261669
|
({ createRuntimeCognitiveTurnLifecycle } = createRequire(import.meta.url)("./bin/cognitive-turn-lifecycle.cjs"));
|
|
@@ -262422,6 +262422,8 @@ var init_turn = __esmMin((() => {
|
|
|
262422
262422
|
const turnRequiredToolNames = new Set(requiredToolNames);
|
|
262423
262423
|
const rankedToolNames = rankedToolNamesForTurnText(eligibleTools, turnText);
|
|
262424
262424
|
for (const name of rankedToolNames) turnRequiredToolNames.add(name);
|
|
262425
|
+
const supportToolNames = rankedSupportToolNamesForGoal(eligibleTools, this.agent.goal.getGoal().goal, origin);
|
|
262426
|
+
for (const name of supportToolNames) turnRequiredToolNames.add(name);
|
|
262425
262427
|
const toolSelection = fastConversation ? {
|
|
262426
262428
|
tools: [...blunFastConversationTools(eligibleTools, input, pendingMediaJobIds, turnRequiredToolNames)],
|
|
262427
262429
|
deferredToolCount: 0
|