blun-king-cli 9.1.166 → 9.1.168
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.
|
@@ -8,9 +8,7 @@ const ASSISTANT_MESSAGE_OFFLOAD_MARKER = '[Assistant message offloaded]';
|
|
|
8
8
|
const ASSISTANT_TOOL_NARRATION_MIN_CHARS = 120;
|
|
9
9
|
const ASSISTANT_TOOL_NARRATION_MARKER = '[Earlier completed tool-step narration compacted]';
|
|
10
10
|
const ASSISTANT_POST_TELEGRAM_REPLY_MARKER = '[Earlier post-reply status compacted]';
|
|
11
|
-
const
|
|
12
|
-
const ASSISTANT_TOOL_ARGUMENT_MIN_TOKENS = 100;
|
|
13
|
-
const ASSISTANT_TOOL_ARGUMENT_MARKER = JSON.stringify({
|
|
11
|
+
const SYNTHETIC_TOOL_ARGUMENT_MARKER = JSON.stringify({
|
|
14
12
|
_blun_compacted: '[Old tool call arguments cleared]',
|
|
15
13
|
});
|
|
16
14
|
const TELEGRAM_REPLY_TOOL_RE = /^mcp__[^\s]*telegram[^\s]*__reply$/iu;
|
|
@@ -108,46 +106,30 @@ function compactHistoricalPostTelegramReplyNarration(messages) {
|
|
|
108
106
|
return changed ? projected : messages;
|
|
109
107
|
}
|
|
110
108
|
|
|
111
|
-
function
|
|
109
|
+
function removeSyntheticToolArgumentFailures(messages) {
|
|
112
110
|
if (!Array.isArray(messages) || messages.length === 0) return messages;
|
|
113
111
|
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const projected = messages.map((message, historyIndex) => {
|
|
123
|
-
if (
|
|
124
|
-
historyIndex >= recentStart
|
|
125
|
-
|| message?.role !== 'assistant'
|
|
126
|
-
|| !Array.isArray(message.toolCalls)
|
|
127
|
-
|| message.toolCalls.length === 0
|
|
128
|
-
) return message;
|
|
112
|
+
const syntheticCallIds = new Set(messages.flatMap((message) => (
|
|
113
|
+
message?.role === 'assistant' && Array.isArray(message.toolCalls)
|
|
114
|
+
? message.toolCalls
|
|
115
|
+
.filter((call) => call?.arguments === SYNTHETIC_TOOL_ARGUMENT_MARKER)
|
|
116
|
+
.map((call) => call?.id)
|
|
117
|
+
: []
|
|
118
|
+
)).filter((id) => typeof id === 'string' && id.length > 0));
|
|
119
|
+
if (syntheticCallIds.size === 0) return messages;
|
|
129
120
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
!completedToolCallIds.has(call?.id)
|
|
134
|
-
|| typeof call?.arguments !== 'string'
|
|
135
|
-
|| Math.ceil(call.arguments.length / 4) < ASSISTANT_TOOL_ARGUMENT_MIN_TOKENS
|
|
136
|
-
) return call;
|
|
137
|
-
try {
|
|
138
|
-
JSON.parse(call.arguments);
|
|
139
|
-
} catch {
|
|
140
|
-
return call;
|
|
141
|
-
}
|
|
142
|
-
toolCallsChanged = true;
|
|
143
|
-
return { ...call, arguments: ASSISTANT_TOOL_ARGUMENT_MARKER };
|
|
144
|
-
});
|
|
145
|
-
if (!toolCallsChanged) return message;
|
|
146
|
-
changed = true;
|
|
147
|
-
return { ...message, toolCalls };
|
|
148
|
-
});
|
|
121
|
+
return messages.flatMap((message) => {
|
|
122
|
+
if (message?.role === 'tool' && syntheticCallIds.has(message.toolCallId)) return [];
|
|
123
|
+
if (message?.role !== 'assistant' || !Array.isArray(message.toolCalls)) return [message];
|
|
149
124
|
|
|
150
|
-
|
|
125
|
+
const toolCalls = message.toolCalls.filter((call) => !syntheticCallIds.has(call?.id));
|
|
126
|
+
if (toolCalls.length === message.toolCalls.length) return [message];
|
|
127
|
+
const hasContent = Array.isArray(message.content)
|
|
128
|
+
? message.content.some((part) => part?.type !== 'text' || String(part?.text ?? '').length > 0)
|
|
129
|
+
: String(message.content ?? '').length > 0;
|
|
130
|
+
if (toolCalls.length === 0 && !hasContent) return [];
|
|
131
|
+
return [{ ...message, toolCalls }];
|
|
132
|
+
});
|
|
151
133
|
}
|
|
152
134
|
|
|
153
135
|
module.exports = {
|
|
@@ -159,12 +141,9 @@ module.exports = {
|
|
|
159
141
|
ASSISTANT_TOOL_NARRATION_MARKER,
|
|
160
142
|
ASSISTANT_TOOL_NARRATION_MIN_CHARS,
|
|
161
143
|
ASSISTANT_POST_TELEGRAM_REPLY_MARKER,
|
|
162
|
-
ASSISTANT_TOOL_ARGUMENT_KEEP_RECENT_MESSAGES,
|
|
163
|
-
ASSISTANT_TOOL_ARGUMENT_MARKER,
|
|
164
|
-
ASSISTANT_TOOL_ARGUMENT_MIN_TOKENS,
|
|
165
|
-
compactHistoricalCompletedToolCallArguments,
|
|
166
144
|
compactHistoricalPostTelegramReplyNarration,
|
|
167
145
|
createAssistantMessagePreview,
|
|
146
|
+
removeSyntheticToolArgumentFailures,
|
|
168
147
|
shouldCompactHistoricalAssistantToolNarration,
|
|
169
148
|
shouldOffloadHistoricalAssistantMessage,
|
|
170
149
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const MICRO_COMPACTION_PRESSURE_RATIO = 0.75;
|
|
4
4
|
const MICRO_COMPACTION_MIN_ADVANCE_MESSAGES = 20;
|
|
5
5
|
const MICRO_COMPACTION_RECENT_MESSAGES = 4;
|
|
6
|
+
const MICRO_COMPACTION_TOOL_ARGUMENTS_ENABLED = false;
|
|
6
7
|
const MICRO_COMPACTION_TOOL_ARGUMENT_MIN_TOKENS = 32;
|
|
7
8
|
|
|
8
9
|
function selectMicroCompactionCutoff(options = {}) {
|
|
@@ -74,6 +75,7 @@ module.exports = {
|
|
|
74
75
|
MICRO_COMPACTION_MIN_ADVANCE_MESSAGES,
|
|
75
76
|
MICRO_COMPACTION_PRESSURE_RATIO,
|
|
76
77
|
MICRO_COMPACTION_RECENT_MESSAGES,
|
|
78
|
+
MICRO_COMPACTION_TOOL_ARGUMENTS_ENABLED,
|
|
77
79
|
MICRO_COMPACTION_TOOL_ARGUMENT_MIN_TOKENS,
|
|
78
80
|
selectMicroCompactionCutoff,
|
|
79
81
|
};
|
|
@@ -75,7 +75,7 @@ function projectRecurringCronHistory(history, jobId) {
|
|
|
75
75
|
if (
|
|
76
76
|
nextMessages > RECURRING_CRON_CONTEXT_MAX_MESSAGES
|
|
77
77
|
|| nextChars > RECURRING_CRON_CONTEXT_MAX_CHARS
|
|
78
|
-
)
|
|
78
|
+
) break;
|
|
79
79
|
selected.unshift(segment);
|
|
80
80
|
selectedMessages = nextMessages;
|
|
81
81
|
selectedChars = nextChars;
|
package/blun.mjs
CHANGED
|
@@ -75985,9 +75985,9 @@ var init_full = __esmMin((() => {
|
|
|
75985
75985
|
}));
|
|
75986
75986
|
//#endregion
|
|
75987
75987
|
//#region ../../packages/agent-core/src/agent/compaction/micro.ts
|
|
75988
|
-
var selectMicroCompactionCutoff, MICRO_COMPACTION_RECENT_MESSAGES, MICRO_COMPACTION_TOOL_ARGUMENT_MIN_TOKENS, isPersistedToolResultReference, projectHistoricalUnaddressedTelegramMessages, compactHistoricalSkillActivations, dedupeRecurringCronWakeups, dedupeRepeatedInjections, DEFAULT_CONFIG, MicroCompaction;
|
|
75988
|
+
var selectMicroCompactionCutoff, MICRO_COMPACTION_RECENT_MESSAGES, MICRO_COMPACTION_TOOL_ARGUMENTS_ENABLED, MICRO_COMPACTION_TOOL_ARGUMENT_MIN_TOKENS, isPersistedToolResultReference, projectHistoricalUnaddressedTelegramMessages, compactHistoricalSkillActivations, dedupeRecurringCronWakeups, dedupeRepeatedInjections, DEFAULT_CONFIG, MicroCompaction;
|
|
75989
75989
|
var init_micro = __esmMin((() => {
|
|
75990
|
-
({ selectMicroCompactionCutoff, MICRO_COMPACTION_RECENT_MESSAGES, MICRO_COMPACTION_TOOL_ARGUMENT_MIN_TOKENS } = createRequire(import.meta.url)("./bin/micro-compaction-policy.cjs"));
|
|
75990
|
+
({ selectMicroCompactionCutoff, MICRO_COMPACTION_RECENT_MESSAGES, MICRO_COMPACTION_TOOL_ARGUMENTS_ENABLED, MICRO_COMPACTION_TOOL_ARGUMENT_MIN_TOKENS } = createRequire(import.meta.url)("./bin/micro-compaction-policy.cjs"));
|
|
75991
75991
|
({ isPersistedToolResultReference } = createRequire(import.meta.url)("./bin/tool-result-offload-policy.cjs"));
|
|
75992
75992
|
({ projectHistoricalUnaddressedTelegramMessages } = createRequire(import.meta.url)("./bin/telegram-context-projection-policy.cjs"));
|
|
75993
75993
|
({ compactHistoricalSkillActivations } = createRequire(import.meta.url)("./bin/skill-activation-performance-policy.cjs"));
|
|
@@ -75996,6 +75996,7 @@ var init_micro = __esmMin((() => {
|
|
|
75996
75996
|
DEFAULT_CONFIG = {
|
|
75997
75997
|
keepRecentMessages: MICRO_COMPACTION_RECENT_MESSAGES,
|
|
75998
75998
|
minContentTokens: 100,
|
|
75999
|
+
compactToolArguments: MICRO_COMPACTION_TOOL_ARGUMENTS_ENABLED,
|
|
75999
76000
|
minToolArgumentTokens: MICRO_COMPACTION_TOOL_ARGUMENT_MIN_TOKENS,
|
|
76000
76001
|
cacheMissedThresholdMs: 3600 * 1e3,
|
|
76001
76002
|
truncatedMarker: "[Old tool result content cleared]",
|
|
@@ -76091,7 +76092,7 @@ var init_micro = __esmMin((() => {
|
|
|
76091
76092
|
text: config.truncatedMarker
|
|
76092
76093
|
}]
|
|
76093
76094
|
});
|
|
76094
|
-
else if (i < historicalArgumentCutoff && msg.role === "assistant" && Array.isArray(msg.toolCalls)) {
|
|
76095
|
+
else if (config.compactToolArguments && i < historicalArgumentCutoff && msg.role === "assistant" && Array.isArray(msg.toolCalls)) {
|
|
76095
76096
|
let changed = false;
|
|
76096
76097
|
const toolCalls = msg.toolCalls.map((call) => {
|
|
76097
76098
|
if (!completedToolCallIds.has(call.id) || typeof call.arguments !== "string" || this.toolArgumentTokens(call.arguments) < config.minToolArgumentTokens) return call;
|
|
@@ -76141,7 +76142,7 @@ var init_micro = __esmMin((() => {
|
|
|
76141
76142
|
truncatedToolResultTokensAfter += markerTokenCount;
|
|
76142
76143
|
}
|
|
76143
76144
|
}
|
|
76144
|
-
if (message?.role !== "assistant" || !Array.isArray(message.toolCalls)) continue;
|
|
76145
|
+
if (!this.config.compactToolArguments || message?.role !== "assistant" || !Array.isArray(message.toolCalls)) continue;
|
|
76145
76146
|
for (const call of message.toolCalls) {
|
|
76146
76147
|
if (!completedToolCallIds.has(call.id) || typeof call.arguments !== "string") continue;
|
|
76147
76148
|
try {
|
|
@@ -260750,7 +260751,7 @@ function renderPersistedAssistantMessage(text, outputPath) {
|
|
|
260750
260751
|
createAssistantMessagePreview(text)
|
|
260751
260752
|
].join("\n");
|
|
260752
260753
|
}
|
|
260753
|
-
var ASSISTANT_MESSAGE_MAX_CHARS, ASSISTANT_MESSAGE_OFFLOAD_MARKER, ASSISTANT_TOOL_NARRATION_MARKER, shouldOffloadHistoricalAssistantMessage, shouldCompactHistoricalAssistantToolNarration, compactHistoricalPostTelegramReplyNarration,
|
|
260754
|
+
var ASSISTANT_MESSAGE_MAX_CHARS, ASSISTANT_MESSAGE_OFFLOAD_MARKER, ASSISTANT_TOOL_NARRATION_MARKER, shouldOffloadHistoricalAssistantMessage, shouldCompactHistoricalAssistantToolNarration, compactHistoricalPostTelegramReplyNarration, removeSyntheticToolArgumentFailures, createAssistantMessagePreview;
|
|
260754
260755
|
var init_assistant_message_offload = __esmMin((() => {
|
|
260755
260756
|
const policy = createRequire(import.meta.url)("./bin/assistant-message-offload-policy.cjs");
|
|
260756
260757
|
ASSISTANT_MESSAGE_MAX_CHARS = policy.ASSISTANT_MESSAGE_MAX_CHARS;
|
|
@@ -260759,7 +260760,7 @@ var init_assistant_message_offload = __esmMin((() => {
|
|
|
260759
260760
|
shouldOffloadHistoricalAssistantMessage = policy.shouldOffloadHistoricalAssistantMessage;
|
|
260760
260761
|
shouldCompactHistoricalAssistantToolNarration = policy.shouldCompactHistoricalAssistantToolNarration;
|
|
260761
260762
|
compactHistoricalPostTelegramReplyNarration = policy.compactHistoricalPostTelegramReplyNarration;
|
|
260762
|
-
|
|
260763
|
+
removeSyntheticToolArgumentFailures = policy.removeSyntheticToolArgumentFailures;
|
|
260763
260764
|
createAssistantMessagePreview = policy.createAssistantMessagePreview;
|
|
260764
260765
|
}));
|
|
260765
260766
|
var AssistantMessageOffload = class {
|
|
@@ -260846,7 +260847,7 @@ var AssistantMessageOffload = class {
|
|
|
260846
260847
|
return { ...message, content: replacement.content };
|
|
260847
260848
|
});
|
|
260848
260849
|
const narrationProjected = compactHistoricalPostTelegramReplyNarration(changed ? projected : messages);
|
|
260849
|
-
return
|
|
260850
|
+
return removeSyntheticToolArgumentFailures(narrationProjected);
|
|
260850
260851
|
}
|
|
260851
260852
|
reset(history = this.agent.context?.history ?? []) {
|
|
260852
260853
|
const activeHashes = new Set(history.map((message) => {
|