blun-king-cli 9.1.217 → 9.1.219
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,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
isLowInformationPersonalMemoryQuery,
|
|
5
|
+
} = require('./personal-memory-performance-policy.cjs');
|
|
6
|
+
|
|
7
|
+
function isRealUserMessage(message) {
|
|
8
|
+
if (message?.role !== 'user') return false;
|
|
9
|
+
const kind = message.origin?.kind;
|
|
10
|
+
return kind !== 'injection' && kind !== 'compaction_summary' && kind !== 'system_trigger';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function textFromMessage(message) {
|
|
14
|
+
if (typeof message?.content === 'string') return message.content.trim();
|
|
15
|
+
if (!Array.isArray(message?.content)) return '';
|
|
16
|
+
return message.content
|
|
17
|
+
.filter((part) => part?.type === 'text' && typeof part.text === 'string')
|
|
18
|
+
.map((part) => part.text.trim())
|
|
19
|
+
.filter(Boolean)
|
|
20
|
+
.join('\n');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function directMessageText(value) {
|
|
24
|
+
let text = value.trim();
|
|
25
|
+
const marker = /^#?\s*\[tg\s+dm\b[^\]]*\]\s*/iu;
|
|
26
|
+
if (!marker.test(text)) return text;
|
|
27
|
+
text = text.replace(marker, '');
|
|
28
|
+
text = text.replace(/^[^\r\n]{1,160}\s+schrieb:\s*/iu, '');
|
|
29
|
+
return text.replace(/\r?\nWeiter-Signal:\s*[\s\S]*$/iu, '').trim();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function hasToolActivityAfter(history, userIndex) {
|
|
33
|
+
return history.slice(userIndex + 1).some((message) => (
|
|
34
|
+
message?.role === 'tool'
|
|
35
|
+
|| (message?.role === 'assistant'
|
|
36
|
+
&& (Array.isArray(message.toolCalls) || Array.isArray(message.tool_calls))
|
|
37
|
+
&& (message.toolCalls?.length > 0 || message.tool_calls?.length > 0))
|
|
38
|
+
));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function shouldSyncValidatedLearningCandidate(history) {
|
|
42
|
+
if (!Array.isArray(history)) return true;
|
|
43
|
+
const userIndex = history.findLastIndex(isRealUserMessage);
|
|
44
|
+
if (userIndex < 0 || hasToolActivityAfter(history, userIndex)) return true;
|
|
45
|
+
const message = history[userIndex];
|
|
46
|
+
if (Array.isArray(message.content)) {
|
|
47
|
+
const hasAttachment = message.content.some((part) => part?.type !== 'text' && part?.type !== 'think');
|
|
48
|
+
if (hasAttachment) return true;
|
|
49
|
+
}
|
|
50
|
+
return !isLowInformationPersonalMemoryQuery(directMessageText(textFromMessage(message)));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { shouldSyncValidatedLearningCandidate };
|
|
@@ -206,9 +206,25 @@ function markCandidate(candidate, status, nowIso) {
|
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
function verificationCommandHash(signal) {
|
|
210
|
+
return crypto.createHash('sha256').update(signal.command).digest('hex');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function pendingCandidateForSignal(candidates, signal) {
|
|
214
|
+
const commandHash = verificationCommandHash(signal);
|
|
215
|
+
for (let index = candidates.length - 1; index >= 0; index -= 1) {
|
|
216
|
+
const candidate = candidates[index];
|
|
217
|
+
if (candidate.status === 'pending'
|
|
218
|
+
&& candidate.verification?.commandHash === commandHash) {
|
|
219
|
+
return candidate;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
|
|
209
225
|
function createCandidate(signal, options, nowIso) {
|
|
210
226
|
const profile = profileKey(options.profile);
|
|
211
|
-
const commandHash =
|
|
227
|
+
const commandHash = verificationCommandHash(signal);
|
|
212
228
|
const digest = crypto.createHash('sha256').update([
|
|
213
229
|
profile,
|
|
214
230
|
commandHash,
|
|
@@ -264,20 +280,27 @@ function syncValidatedLearningCandidate(history, options = {}) {
|
|
|
264
280
|
if (recordedCandidateIds.size > 0) {
|
|
265
281
|
candidates = readValidatedLearningCandidates({ homeDir, profile: options.profile });
|
|
266
282
|
}
|
|
267
|
-
|
|
268
|
-
return {
|
|
269
|
-
...createCandidate(signal, { homeDir, profile: options.profile }, nowIso),
|
|
270
|
-
source: 'current_turn',
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
283
|
+
let expiredCandidate = false;
|
|
274
284
|
for (const candidate of candidates) {
|
|
275
285
|
if (candidate.status !== 'pending') continue;
|
|
276
286
|
if (nowMs - Date.parse(candidate.createdAt) >= CANDIDATE_TTL_MS) {
|
|
277
287
|
markCandidate(candidate, 'expired', nowIso);
|
|
288
|
+
expiredCandidate = true;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (expiredCandidate) {
|
|
292
|
+
candidates = readValidatedLearningCandidates({ homeDir, profile: options.profile });
|
|
293
|
+
}
|
|
294
|
+
if (signal !== null) {
|
|
295
|
+
const duplicate = pendingCandidateForSignal(candidates, signal);
|
|
296
|
+
if (duplicate !== null) {
|
|
297
|
+
return { ...duplicate, source: 'current_turn' };
|
|
278
298
|
}
|
|
299
|
+
return {
|
|
300
|
+
...createCandidate(signal, { homeDir, profile: options.profile }, nowIso),
|
|
301
|
+
source: 'current_turn',
|
|
302
|
+
};
|
|
279
303
|
}
|
|
280
|
-
candidates = readValidatedLearningCandidates({ homeDir, profile: options.profile });
|
|
281
304
|
const pending = newestPending(candidates);
|
|
282
305
|
return pending === null ? null : { ...pending, source: 'persisted' };
|
|
283
306
|
} catch {
|
package/blun.mjs
CHANGED
|
@@ -232151,18 +232151,20 @@ function buildValidatedLearningSignalReminder(signal) {
|
|
|
232151
232151
|
lines.push("</validated-learning-signal>");
|
|
232152
232152
|
return lines.join("\n");
|
|
232153
232153
|
}
|
|
232154
|
-
var ValidatedLearningSignalInjector, syncValidatedLearningCandidate;
|
|
232154
|
+
var ValidatedLearningSignalInjector, shouldSyncValidatedLearningCandidate, syncValidatedLearningCandidate;
|
|
232155
232155
|
var init_validated_learning_signal = __esmMin((() => {
|
|
232156
232156
|
init_injector();
|
|
232157
232157
|
({ syncValidatedLearningCandidate } = createRequire(import.meta.url)("./bin/validated-learning-signal.cjs"));
|
|
232158
|
+
({ shouldSyncValidatedLearningCandidate } = createRequire(import.meta.url)("./bin/validated-learning-performance-policy.cjs"));
|
|
232158
232159
|
ValidatedLearningSignalInjector = class extends DynamicInjector {
|
|
232159
232160
|
injectionVariant = "validated_learning_signal";
|
|
232160
232161
|
async inject() {
|
|
232162
|
+
const existing = this.agent.context.history.filter(isValidatedLearningSignalReminder);
|
|
232163
|
+
if (!shouldSyncValidatedLearningCandidate(this.agent.context.history)) return;
|
|
232161
232164
|
const signal = syncValidatedLearningCandidate(this.agent.context.history, {
|
|
232162
232165
|
homeDir: process.env["BLUN_SHARED_HOME"] ?? process.env["BLUN_HOME"] ?? "",
|
|
232163
232166
|
profile: process.env["BLUN_PROFILE"] ?? "default"
|
|
232164
232167
|
});
|
|
232165
|
-
const existing = this.agent.context.history.filter(isValidatedLearningSignalReminder);
|
|
232166
232168
|
if (signal === null) {
|
|
232167
232169
|
if (existing.length > 0) this.agent.context.removeSystemRemindersMatching(isValidatedLearningSignalReminder);
|
|
232168
232170
|
return;
|