@cortexkit/pi-magic-context 0.43.2 → 0.44.0
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/dist/{index-mea04n1j.js → index-2kj55q4e.js} +88 -26
- package/dist/{index-bkrh6jhp.js → index-8ytss1hp.js} +308 -190
- package/dist/{index-5v60m046.js → index-jscq7067.js} +1 -1
- package/dist/{index-17102c1m.js → index-mmkdxa5j.js} +1 -1
- package/dist/{index-bfd52y8p.js → index-tfzybajk.js} +22 -6
- package/dist/index.js +1142 -364
- package/dist/{message-time-backfill-f0v3yvza.js → message-time-backfill-3rp0w2z9.js} +3 -3
- package/dist/{read-session-chunk-ky2sprnf.js → read-session-chunk-2s116ah5.js} +4 -2
- package/dist/{safe-notification-target-d7f3t5qk.js → safe-notification-target-pd09ybr0.js} +2 -2
- package/dist/subagent-entry.js +4 -4
- package/package.json +4 -2
|
@@ -320,6 +320,15 @@ var buffer = [];
|
|
|
320
320
|
var flushTimer = null;
|
|
321
321
|
var FLUSH_INTERVAL_MS = 500;
|
|
322
322
|
var BUFFER_SIZE_LIMIT = 50;
|
|
323
|
+
var MAX_BUFFERED_BYTES = 1024 * 1024;
|
|
324
|
+
var bufferedBytes = 0;
|
|
325
|
+
var droppedLines = 0;
|
|
326
|
+
function boundBuffer() {
|
|
327
|
+
while (bufferedBytes > MAX_BUFFERED_BYTES && buffer.length > 0) {
|
|
328
|
+
bufferedBytes -= Buffer.byteLength(buffer.shift() ?? "");
|
|
329
|
+
droppedLines++;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
323
332
|
var MAX_LOG_FILE_BYTES = 32 * 1024 * 1024;
|
|
324
333
|
var SIZE_CHECK_INTERVAL_FLUSHES = 64;
|
|
325
334
|
var activeLogFile = null;
|
|
@@ -410,12 +419,12 @@ function flush() {
|
|
|
410
419
|
clearTimeout(flushTimer);
|
|
411
420
|
flushTimer = null;
|
|
412
421
|
}
|
|
413
|
-
if (buffer.length === 0)
|
|
422
|
+
if (buffer.length === 0 && droppedLines === 0)
|
|
414
423
|
return;
|
|
415
|
-
const
|
|
416
|
-
|
|
424
|
+
const notice = droppedLines ? `[${new Date().toISOString()}] [magic-context][global] logger dropped ${droppedLines} ${droppedLines === 1 ? "line" : "lines"}: buffer exceeded ${MAX_BUFFERED_BYTES} bytes while writes were pending
|
|
425
|
+
` : "";
|
|
417
426
|
try {
|
|
418
|
-
const data = capLogData(
|
|
427
|
+
const data = capLogData(notice + buffer.join(""));
|
|
419
428
|
const logFile = getMagicContextLogPath();
|
|
420
429
|
ensureDir(logFile);
|
|
421
430
|
let currentSize = getCurrentLogSize(logFile);
|
|
@@ -425,6 +434,9 @@ function flush() {
|
|
|
425
434
|
currentSize = 0;
|
|
426
435
|
}
|
|
427
436
|
fs.appendFileSync(logFile, data, { encoding: "utf8", mode: 384 });
|
|
437
|
+
buffer = [];
|
|
438
|
+
bufferedBytes = 0;
|
|
439
|
+
droppedLines = 0;
|
|
428
440
|
activeLogFile = logFile;
|
|
429
441
|
activeLogSize = currentSize + dataSize;
|
|
430
442
|
flushesSinceSizeCheck++;
|
|
@@ -433,6 +445,7 @@ function flush() {
|
|
|
433
445
|
activeLogSize = null;
|
|
434
446
|
flushesSinceSizeCheck = 0;
|
|
435
447
|
recordSwallowedWrite(error);
|
|
448
|
+
boundBuffer();
|
|
436
449
|
}
|
|
437
450
|
}
|
|
438
451
|
function scheduleFlush() {
|
|
@@ -450,8 +463,11 @@ function log(message, data) {
|
|
|
450
463
|
const timestamp = new Date().toISOString();
|
|
451
464
|
const serialized = data === undefined ? "" : data instanceof Error ? ` ${sanitizeDiagnosticText(`${data.message}${data.stack ? `
|
|
452
465
|
${data.stack}` : ""}`)}` : ` ${JSON.stringify(sanitizeConfigValue(data))}`;
|
|
453
|
-
|
|
454
|
-
|
|
466
|
+
const line = `[${timestamp}] ${sanitizeDiagnosticText(message)}${serialized}
|
|
467
|
+
`;
|
|
468
|
+
buffer.push(line);
|
|
469
|
+
bufferedBytes += Buffer.byteLength(line);
|
|
470
|
+
boundBuffer();
|
|
455
471
|
if (buffer.length >= BUFFER_SIZE_LIMIT) {
|
|
456
472
|
flush();
|
|
457
473
|
} else {
|