blun-king-cli 9.1.164 → 9.1.166
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,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const RECURRING_CRON_CONTEXT_MAX_MESSAGES = 24;
|
|
4
|
+
const RECURRING_CRON_CONTEXT_MAX_CHARS = 48_000;
|
|
5
|
+
|
|
6
|
+
function recurringCronJobId(message) {
|
|
7
|
+
if (message?.role !== 'user') return null;
|
|
8
|
+
if (message.origin?.kind !== 'cron_job' || message.origin.recurring !== true) return null;
|
|
9
|
+
const jobId = String(message.origin.jobId || '').trim();
|
|
10
|
+
return jobId || null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function messageTextChars(message) {
|
|
14
|
+
if (!Array.isArray(message?.content)) return 0;
|
|
15
|
+
return message.content.reduce((total, part) => (
|
|
16
|
+
total + (part?.type === 'text' && typeof part.text === 'string' ? part.text.length : 0)
|
|
17
|
+
), 0);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function splitIntoUserSegments(messages) {
|
|
21
|
+
const segments = [];
|
|
22
|
+
let current = [];
|
|
23
|
+
for (const message of messages) {
|
|
24
|
+
if (message?.role === 'user' && current.length > 0) {
|
|
25
|
+
segments.push(current);
|
|
26
|
+
current = [];
|
|
27
|
+
}
|
|
28
|
+
current.push(message);
|
|
29
|
+
}
|
|
30
|
+
if (current.length > 0) segments.push(current);
|
|
31
|
+
return segments;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function segmentTextChars(segment) {
|
|
35
|
+
return segment.reduce((total, message) => total + messageTextChars(message), 0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isCompactionSummarySegment(segment) {
|
|
39
|
+
return segment[0]?.role === 'user' && segment[0]?.origin?.kind === 'compaction_summary';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isRecurringCronSegment(segment) {
|
|
43
|
+
return recurringCronJobId(segment[0]) !== null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function projectRecurringCronHistory(history, jobId) {
|
|
47
|
+
if (!Array.isArray(history) || history.length === 0) return history;
|
|
48
|
+
const normalizedJobId = String(jobId || '').trim();
|
|
49
|
+
if (!normalizedJobId) return history;
|
|
50
|
+
|
|
51
|
+
let wakeupIndex = -1;
|
|
52
|
+
for (let index = history.length - 1; index >= 0; index -= 1) {
|
|
53
|
+
if (recurringCronJobId(history[index]) === normalizedJobId) {
|
|
54
|
+
wakeupIndex = index;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (wakeupIndex < 0) return history;
|
|
59
|
+
|
|
60
|
+
const currentSegment = history.slice(wakeupIndex);
|
|
61
|
+
const priorSegments = splitIntoUserSegments(history.slice(0, wakeupIndex));
|
|
62
|
+
const summaryIndex = priorSegments.findLastIndex(isCompactionSummarySegment);
|
|
63
|
+
const summary = summaryIndex >= 0 ? priorSegments[summaryIndex] : [];
|
|
64
|
+
const candidates = priorSegments.filter((segment, index) => (
|
|
65
|
+
index !== summaryIndex && !isRecurringCronSegment(segment)
|
|
66
|
+
));
|
|
67
|
+
|
|
68
|
+
const selected = [];
|
|
69
|
+
let selectedMessages = summary.length + currentSegment.length;
|
|
70
|
+
let selectedChars = segmentTextChars(summary) + segmentTextChars(currentSegment);
|
|
71
|
+
for (let index = candidates.length - 1; index >= 0; index -= 1) {
|
|
72
|
+
const segment = candidates[index];
|
|
73
|
+
const nextMessages = selectedMessages + segment.length;
|
|
74
|
+
const nextChars = selectedChars + segmentTextChars(segment);
|
|
75
|
+
if (
|
|
76
|
+
nextMessages > RECURRING_CRON_CONTEXT_MAX_MESSAGES
|
|
77
|
+
|| nextChars > RECURRING_CRON_CONTEXT_MAX_CHARS
|
|
78
|
+
) continue;
|
|
79
|
+
selected.unshift(segment);
|
|
80
|
+
selectedMessages = nextMessages;
|
|
81
|
+
selectedChars = nextChars;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return [...summary, ...selected.flat(), ...currentSegment];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = {
|
|
88
|
+
RECURRING_CRON_CONTEXT_MAX_CHARS,
|
|
89
|
+
RECURRING_CRON_CONTEXT_MAX_MESSAGES,
|
|
90
|
+
projectRecurringCronHistory,
|
|
91
|
+
recurringCronJobId,
|
|
92
|
+
};
|
|
@@ -8,6 +8,7 @@ const STATUS_ONLY_CHECK_IN = /(?:\bstandabfrage\b|\bstatusabfrage\b|\bkurzes?\s+
|
|
|
8
8
|
const STATUS_FOLLOW_UP_ACTION = /\b(?:aendere|arbeite|baue|build|change|delete|deploy|deploye|fahr|fix|fixe|implement|implementiere|install|installiere|loesche|mach|patch|pruefe|repariere|run|schreibe|setze|start|starte|stop|stoppe|test|teste|write)\b/iu;
|
|
9
9
|
const LIGHTWEIGHT_STEER = /\b(?:cool|danke|dankeschoen|gute arbeit|passt|perfekt|stolz|super|freut mich)\b/iu;
|
|
10
10
|
const ADAPTIVE_LOW_COMPLETION_TOKENS = 8192;
|
|
11
|
+
const STANDARD_TURN_MAX_COMPLETION_TOKENS = 24_576;
|
|
11
12
|
|
|
12
13
|
function selectThinkingEffortForTurn(text, originKind) {
|
|
13
14
|
if (originKind !== "user") return undefined;
|
|
@@ -52,6 +53,13 @@ function capCompletionBudgetForAdaptiveEffort(budget, thinkingEffort) {
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
function capTurnCompletionTokens(maxOutputSize) {
|
|
57
|
+
if (!Number.isFinite(maxOutputSize) || maxOutputSize <= 0) {
|
|
58
|
+
return STANDARD_TURN_MAX_COMPLETION_TOKENS;
|
|
59
|
+
}
|
|
60
|
+
return Math.min(Math.floor(maxOutputSize), STANDARD_TURN_MAX_COMPLETION_TOKENS);
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
function selectThinkingEffortForBufferedSteer(text, originKind) {
|
|
56
64
|
const classified = selectThinkingEffortForTurn(text, originKind);
|
|
57
65
|
if (classified !== undefined) return classified;
|
|
@@ -73,7 +81,9 @@ module.exports = {
|
|
|
73
81
|
ACTIONABLE_PROMPT,
|
|
74
82
|
ADAPTIVE_LOW_COMPLETION_TOKENS,
|
|
75
83
|
EXPLICIT_THINKING_INTENT,
|
|
84
|
+
STANDARD_TURN_MAX_COMPLETION_TOKENS,
|
|
76
85
|
capCompletionBudgetForAdaptiveEffort,
|
|
86
|
+
capTurnCompletionTokens,
|
|
77
87
|
selectThinkingEffortForBufferedSteer,
|
|
78
88
|
selectThinkingEffortForWorkStep,
|
|
79
89
|
selectThinkingEffortForTurn,
|
package/blun.mjs
CHANGED
|
@@ -261180,7 +261180,7 @@ function toolResultText(result) {
|
|
|
261180
261180
|
function abandonedToolResultOutput(ended) {
|
|
261181
261181
|
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.`;
|
|
261182
261182
|
}
|
|
261183
|
-
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, toolSchemaBudgetTokens, 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;
|
|
261183
|
+
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, toolSchemaBudgetTokens, projectRecurringCronHistory, 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;
|
|
261184
261184
|
var init_turn = __esmMin((() => {
|
|
261185
261185
|
init_dist$4();
|
|
261186
261186
|
init_src$4();
|
|
@@ -261198,6 +261198,7 @@ var init_turn = __esmMin((() => {
|
|
|
261198
261198
|
init_user_message_offload();
|
|
261199
261199
|
init_assistant_message_offload();
|
|
261200
261200
|
({ CORE_TOOL_NAMES: BLUN_CORE_TOOL_NAMES, createDeferredToolLoader, toolSchemaBudgetTokens } = createRequire(import.meta.url)("./bin/turn-tool-performance-policy.cjs"));
|
|
261201
|
+
({ projectRecurringCronHistory } = createRequire(import.meta.url)("./bin/recurring-cron-history-policy.cjs"));
|
|
261201
261202
|
BLUN_LEAN_TOOL_NAMES = new Set(BLUN_CORE_TOOL_NAMES);
|
|
261202
261203
|
BLUN_ATTACHMENT_MARKER_RE = /\b(?:attachment_file_id|telegram-anhang|telegram attachment)\b/i;
|
|
261203
261204
|
BLUN_TELEGRAM_OUTBOUND_TOOL_RE = /^mcp__[^\s]*telegram[^\s]*__(?:reply|react|edit_message)$/i;
|
|
@@ -261807,8 +261808,8 @@ var init_turn = __esmMin((() => {
|
|
|
261807
261808
|
turnId: String(turnId),
|
|
261808
261809
|
signal,
|
|
261809
261810
|
llm: turnLLM,
|
|
261810
|
-
buildMessages: () => this.agent.context.project(fastConversation ? turnThinkingEffort === "off" ? blunStandaloneConversationHistory(this.agent.context.history) : blunFastConversationHistory(this.agent.context.history) : personalMemoryRecall === void 0 ? this.agent.context.history : [...this.agent.context.history, personalMemoryRecall], { dropOrphanResults: true }),
|
|
261811
|
-
buildMessagesStrict: () => this.agent.context.project(fastConversation ? turnThinkingEffort === "off" ? blunStandaloneConversationHistory(this.agent.context.history) : blunFastConversationHistory(this.agent.context.history) : personalMemoryRecall === void 0 ? this.agent.context.history : [...this.agent.context.history, personalMemoryRecall], {
|
|
261811
|
+
buildMessages: () => this.agent.context.project(fastConversation ? turnThinkingEffort === "off" ? blunStandaloneConversationHistory(this.agent.context.history) : blunFastConversationHistory(this.agent.context.history) : origin.kind === "cron_job" && origin.recurring === true ? projectRecurringCronHistory(this.agent.context.history, origin.jobId) : personalMemoryRecall === void 0 ? this.agent.context.history : [...this.agent.context.history, personalMemoryRecall], { dropOrphanResults: true }),
|
|
261812
|
+
buildMessagesStrict: () => this.agent.context.project(fastConversation ? turnThinkingEffort === "off" ? blunStandaloneConversationHistory(this.agent.context.history) : blunFastConversationHistory(this.agent.context.history) : origin.kind === "cron_job" && origin.recurring === true ? projectRecurringCronHistory(this.agent.context.history, origin.jobId) : personalMemoryRecall === void 0 ? this.agent.context.history : [...this.agent.context.history, personalMemoryRecall], {
|
|
261812
261813
|
synthesizeMissing: true,
|
|
261813
261814
|
dropOrphanResults: true,
|
|
261814
261815
|
dedupeDuplicateToolCalls: true,
|
|
@@ -264540,7 +264541,7 @@ var init_llm_request_logger = __esmMin((() => {
|
|
|
264540
264541
|
function normalizeRuntimeSystemPromptAppend(value) {
|
|
264541
264542
|
return value?.trim().slice(0, 16e3) ?? "";
|
|
264542
264543
|
}
|
|
264543
|
-
var PINNED_MODEL_ALIASES, resolveProviderIdleTimeoutMs, capCompletionBudgetForAdaptiveEffort, selectThinkingEffortForBufferedSteer, selectThinkingEffortForWorkStep, selectThinkingEffortForTurn, Agent$1;
|
|
264544
|
+
var PINNED_MODEL_ALIASES, resolveProviderIdleTimeoutMs, capCompletionBudgetForAdaptiveEffort, capTurnCompletionTokens, selectThinkingEffortForBufferedSteer, selectThinkingEffortForWorkStep, selectThinkingEffortForTurn, Agent$1;
|
|
264544
264545
|
var init_agent = __esmMin((() => {
|
|
264545
264546
|
init_dist$6();
|
|
264546
264547
|
init_config$4();
|
|
@@ -264578,7 +264579,7 @@ var init_agent = __esmMin((() => {
|
|
|
264578
264579
|
init_session_loop();
|
|
264579
264580
|
init_error_memory();
|
|
264580
264581
|
({ resolveProviderIdleTimeoutMs } = createRequire(import.meta.url)("./bin/provider-idle-timeout-policy.cjs"));
|
|
264581
|
-
({ capCompletionBudgetForAdaptiveEffort, selectThinkingEffortForBufferedSteer, selectThinkingEffortForWorkStep, selectThinkingEffortForTurn } = createRequire(import.meta.url)("./bin/turn-thinking-policy.cjs"));
|
|
264582
|
+
({ capCompletionBudgetForAdaptiveEffort, capTurnCompletionTokens, selectThinkingEffortForBufferedSteer, selectThinkingEffortForWorkStep, selectThinkingEffortForTurn } = createRequire(import.meta.url)("./bin/turn-thinking-policy.cjs"));
|
|
264582
264583
|
PINNED_MODEL_ALIASES = new Set(["king-blun", "pruefstand"]);
|
|
264583
264584
|
Agent$1 = class {
|
|
264584
264585
|
type;
|
|
@@ -264769,7 +264770,7 @@ var init_agent = __esmMin((() => {
|
|
|
264769
264770
|
const provider = thinkingEffort === void 0 ? runtimeModel.provider : runtimeModel.provider.withThinking(thinkingEffort);
|
|
264770
264771
|
const loopControl = this.blunConfig?.loopControl;
|
|
264771
264772
|
const completionBudgetConfig = resolveCompletionBudget({
|
|
264772
|
-
maxOutputSize: runtimeModel.maxOutputSize,
|
|
264773
|
+
maxOutputSize: capTurnCompletionTokens(runtimeModel.maxOutputSize),
|
|
264773
264774
|
reservedContextSize: loopControl?.reservedContextSize
|
|
264774
264775
|
});
|
|
264775
264776
|
return new KosongLLM({
|