blun-king-cli 9.1.443 → 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.
- package/bin/mistake-relevance-policy.cjs +52 -0
- package/blun.mjs +3 -3
- package/package.json +1 -1
|
@@ -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,
|
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 = "";
|