blun-king-cli 9.1.205 → 9.1.207
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/telemetry-spool-policy.cjs +57 -0
- package/blun.mjs +42 -18
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const TELEMETRY_RETRY_MAX_FILES = 16;
|
|
4
|
+
const TELEMETRY_SPOOL_MAX_FILES = 512;
|
|
5
|
+
const TELEMETRY_SPOOL_MAX_BYTES = 16 * 1024 * 1024;
|
|
6
|
+
const TELEMETRY_SPOOL_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
7
|
+
|
|
8
|
+
function isFailedTelemetryEntry(entry) {
|
|
9
|
+
return entry !== null
|
|
10
|
+
&& typeof entry === 'object'
|
|
11
|
+
&& /^failed_[^.]+\.jsonl$/u.test(entry.name ?? '')
|
|
12
|
+
&& Number.isFinite(entry.mtimeMs)
|
|
13
|
+
&& Number.isFinite(entry.size)
|
|
14
|
+
&& entry.size >= 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function oldestFirst(left, right) {
|
|
18
|
+
return left.mtimeMs - right.mtimeMs || left.name.localeCompare(right.name);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function newestFirst(left, right) {
|
|
22
|
+
return right.mtimeMs - left.mtimeMs || right.name.localeCompare(left.name);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function selectTelemetryRetryEntries(entries, maxFiles = TELEMETRY_RETRY_MAX_FILES) {
|
|
26
|
+
if (!Number.isSafeInteger(maxFiles) || maxFiles < 0) return [];
|
|
27
|
+
return entries.filter(isFailedTelemetryEntry).sort(oldestFirst).slice(0, maxFiles);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function selectTelemetrySpoolPruneEntries(entries, now = Date.now()) {
|
|
31
|
+
const failed = entries.filter(isFailedTelemetryEntry);
|
|
32
|
+
const expired = failed.filter((entry) => now - entry.mtimeMs > TELEMETRY_SPOOL_MAX_AGE_MS);
|
|
33
|
+
const expiredNames = new Set(expired.map((entry) => entry.name));
|
|
34
|
+
const live = failed.filter((entry) => !expiredNames.has(entry.name)).sort(newestFirst);
|
|
35
|
+
const keptNames = new Set();
|
|
36
|
+
let keptBytes = 0;
|
|
37
|
+
|
|
38
|
+
for (const entry of live) {
|
|
39
|
+
if (keptNames.size >= TELEMETRY_SPOOL_MAX_FILES) continue;
|
|
40
|
+
if (keptBytes + entry.size > TELEMETRY_SPOOL_MAX_BYTES) continue;
|
|
41
|
+
keptNames.add(entry.name);
|
|
42
|
+
keptBytes += entry.size;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return failed
|
|
46
|
+
.filter((entry) => expiredNames.has(entry.name) || !keptNames.has(entry.name))
|
|
47
|
+
.sort(oldestFirst);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
TELEMETRY_RETRY_MAX_FILES,
|
|
52
|
+
TELEMETRY_SPOOL_MAX_AGE_MS,
|
|
53
|
+
TELEMETRY_SPOOL_MAX_BYTES,
|
|
54
|
+
TELEMETRY_SPOOL_MAX_FILES,
|
|
55
|
+
selectTelemetryRetryEntries,
|
|
56
|
+
selectTelemetrySpoolPruneEntries,
|
|
57
|
+
};
|
package/blun.mjs
CHANGED
|
@@ -78973,8 +78973,9 @@ var init_context$2 = __esmMin((() => {
|
|
|
78973
78973
|
const historicalUserReferencesProjected = compactHistoricalPersistedUserMessageReferences(userOffloaded);
|
|
78974
78974
|
const duplicateUserMessagesProjected = dedupeRepeatedUserMessages(historicalUserReferencesProjected);
|
|
78975
78975
|
const historicalTelegramProjected = projectHistoricalUnaddressedTelegramMessages(duplicateUserMessagesProjected);
|
|
78976
|
-
const
|
|
78977
|
-
const
|
|
78976
|
+
const assistantOffloaded = this.agent.assistantMessageOffload.compact(historicalTelegramProjected);
|
|
78977
|
+
const repeatedAssistantProjected = projectRepeatedAssistantResponses(assistantOffloaded);
|
|
78978
|
+
const result = project(this.agent.microCompaction.compact(compactHistoricalSuccessfulToolResults(this.agent.toolResultBatchOffload.compact(dedupeRecurringCronWakeups(dedupeRepeatedInjections(compactHistoricalSkillActivations(compactBaselineSkillInjections(repeatedAssistantProjected))))))), {
|
|
78978
78979
|
...options,
|
|
78979
78980
|
onAnomaly: (anomaly) => {
|
|
78980
78981
|
anomalies.push(anomaly);
|
|
@@ -328162,6 +328163,10 @@ const RETRY_BACKOFFS_MS = [
|
|
|
328162
328163
|
16e3
|
|
328163
328164
|
];
|
|
328164
328165
|
const DEFAULT_REQUEST_TIMEOUT_MS = 1e4;
|
|
328166
|
+
const {
|
|
328167
|
+
selectTelemetryRetryEntries,
|
|
328168
|
+
selectTelemetrySpoolPruneEntries
|
|
328169
|
+
} = createRequire(import.meta.url)("./bin/telemetry-spool-policy.cjs");
|
|
328165
328170
|
var AsyncTransport = class {
|
|
328166
328171
|
homeDir;
|
|
328167
328172
|
deviceId;
|
|
@@ -328172,6 +328177,7 @@ var AsyncTransport = class {
|
|
|
328172
328177
|
requestTimeoutMs;
|
|
328173
328178
|
sleepImpl;
|
|
328174
328179
|
now;
|
|
328180
|
+
spoolWritesSincePrune = 0;
|
|
328175
328181
|
constructor(options) {
|
|
328176
328182
|
this.homeDir = options.homeDir;
|
|
328177
328183
|
this.deviceId = options.deviceId;
|
|
@@ -328234,26 +328240,44 @@ var AsyncTransport = class {
|
|
|
328234
328240
|
try {
|
|
328235
328241
|
chmodSync(path, 384);
|
|
328236
328242
|
} catch {}
|
|
328243
|
+
this.spoolWritesSincePrune += 1;
|
|
328244
|
+
if (this.spoolWritesSincePrune === 1 || this.spoolWritesSincePrune >= 64) {
|
|
328245
|
+
this.pruneDiskSpool();
|
|
328246
|
+
this.spoolWritesSincePrune = 0;
|
|
328247
|
+
}
|
|
328237
328248
|
}
|
|
328238
|
-
|
|
328239
|
-
let
|
|
328249
|
+
readSpoolEntries() {
|
|
328250
|
+
let names;
|
|
328240
328251
|
try {
|
|
328241
|
-
|
|
328252
|
+
names = readdirSync(this.telemetryDir());
|
|
328242
328253
|
} catch {
|
|
328243
|
-
return;
|
|
328254
|
+
return [];
|
|
328244
328255
|
}
|
|
328245
|
-
const
|
|
328246
|
-
for (const
|
|
328247
|
-
if (!
|
|
328248
|
-
const path = join(this.telemetryDir(),
|
|
328256
|
+
const entries = [];
|
|
328257
|
+
for (const name of names) {
|
|
328258
|
+
if (!name.startsWith("failed_") || !name.endsWith(".jsonl")) continue;
|
|
328259
|
+
const path = join(this.telemetryDir(), name);
|
|
328249
328260
|
try {
|
|
328250
|
-
|
|
328251
|
-
|
|
328252
|
-
|
|
328253
|
-
|
|
328254
|
-
|
|
328255
|
-
|
|
328256
|
-
|
|
328261
|
+
const stats = statSync(path);
|
|
328262
|
+
entries.push({ name, mtimeMs: stats.mtimeMs, size: stats.size });
|
|
328263
|
+
} catch {}
|
|
328264
|
+
}
|
|
328265
|
+
return entries;
|
|
328266
|
+
}
|
|
328267
|
+
pruneDiskSpool(spoolEntries = this.readSpoolEntries()) {
|
|
328268
|
+
const pruned = selectTelemetrySpoolPruneEntries(spoolEntries, this.now());
|
|
328269
|
+
for (const entry of pruned) try {
|
|
328270
|
+
unlinkSync(join(this.telemetryDir(), entry.name));
|
|
328271
|
+
} catch {}
|
|
328272
|
+
return new Set(pruned.map((entry) => entry.name));
|
|
328273
|
+
}
|
|
328274
|
+
async retryDiskEvents() {
|
|
328275
|
+
const spoolEntries = this.readSpoolEntries();
|
|
328276
|
+
const prunedNames = this.pruneDiskSpool(spoolEntries);
|
|
328277
|
+
const retryEntries = selectTelemetryRetryEntries(spoolEntries
|
|
328278
|
+
.filter((entry) => !prunedNames.has(entry.name)));
|
|
328279
|
+
for (const entry of retryEntries) {
|
|
328280
|
+
const path = join(this.telemetryDir(), entry.name);
|
|
328257
328281
|
let events;
|
|
328258
328282
|
let payload;
|
|
328259
328283
|
try {
|
|
@@ -328269,7 +328293,7 @@ var AsyncTransport = class {
|
|
|
328269
328293
|
await this.sendHttp(payload);
|
|
328270
328294
|
unlinkSync(path);
|
|
328271
328295
|
} catch (error) {
|
|
328272
|
-
if (error instanceof TransientTelemetryError)
|
|
328296
|
+
if (error instanceof TransientTelemetryError) break;
|
|
328273
328297
|
}
|
|
328274
328298
|
}
|
|
328275
328299
|
}
|