@cortexkit/pi-magic-context 0.43.2 → 0.44.1

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.
@@ -11,6 +11,9 @@ function setHarness(value) {
11
11
  function getHarness() {
12
12
  return currentHarness;
13
13
  }
14
+ function harnessOwnsOpenCodeStore(harness = currentHarness) {
15
+ return harness === "opencode" || harness === "opencode2";
16
+ }
14
17
 
15
18
  // ../plugin/src/shared/data-path.ts
16
19
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
@@ -320,6 +323,15 @@ var buffer = [];
320
323
  var flushTimer = null;
321
324
  var FLUSH_INTERVAL_MS = 500;
322
325
  var BUFFER_SIZE_LIMIT = 50;
326
+ var MAX_BUFFERED_BYTES = 1024 * 1024;
327
+ var bufferedBytes = 0;
328
+ var droppedLines = 0;
329
+ function boundBuffer() {
330
+ while (bufferedBytes > MAX_BUFFERED_BYTES && buffer.length > 0) {
331
+ bufferedBytes -= Buffer.byteLength(buffer.shift() ?? "");
332
+ droppedLines++;
333
+ }
334
+ }
323
335
  var MAX_LOG_FILE_BYTES = 32 * 1024 * 1024;
324
336
  var SIZE_CHECK_INTERVAL_FLUSHES = 64;
325
337
  var activeLogFile = null;
@@ -410,12 +422,12 @@ function flush() {
410
422
  clearTimeout(flushTimer);
411
423
  flushTimer = null;
412
424
  }
413
- if (buffer.length === 0)
425
+ if (buffer.length === 0 && droppedLines === 0)
414
426
  return;
415
- const bufferedData = buffer.join("");
416
- buffer = [];
427
+ 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
428
+ ` : "";
417
429
  try {
418
- const data = capLogData(bufferedData);
430
+ const data = capLogData(notice + buffer.join(""));
419
431
  const logFile = getMagicContextLogPath();
420
432
  ensureDir(logFile);
421
433
  let currentSize = getCurrentLogSize(logFile);
@@ -425,6 +437,9 @@ function flush() {
425
437
  currentSize = 0;
426
438
  }
427
439
  fs.appendFileSync(logFile, data, { encoding: "utf8", mode: 384 });
440
+ buffer = [];
441
+ bufferedBytes = 0;
442
+ droppedLines = 0;
428
443
  activeLogFile = logFile;
429
444
  activeLogSize = currentSize + dataSize;
430
445
  flushesSinceSizeCheck++;
@@ -433,6 +448,7 @@ function flush() {
433
448
  activeLogSize = null;
434
449
  flushesSinceSizeCheck = 0;
435
450
  recordSwallowedWrite(error);
451
+ boundBuffer();
436
452
  }
437
453
  }
438
454
  function scheduleFlush() {
@@ -450,8 +466,11 @@ function log(message, data) {
450
466
  const timestamp = new Date().toISOString();
451
467
  const serialized = data === undefined ? "" : data instanceof Error ? ` ${sanitizeDiagnosticText(`${data.message}${data.stack ? `
452
468
  ${data.stack}` : ""}`)}` : ` ${JSON.stringify(sanitizeConfigValue(data))}`;
453
- buffer.push(`[${timestamp}] ${sanitizeDiagnosticText(message)}${serialized}
454
- `);
469
+ const line = `[${timestamp}] ${sanitizeDiagnosticText(message)}${serialized}
470
+ `;
471
+ buffer.push(line);
472
+ bufferedBytes += Buffer.byteLength(line);
473
+ boundBuffer();
455
474
  if (buffer.length >= BUFFER_SIZE_LIMIT) {
456
475
  flush();
457
476
  } else {
@@ -469,4 +488,4 @@ if (!isTestEnv) {
469
488
  process.on("exit", flush);
470
489
  }
471
490
 
472
- export { setHarness, getHarness, getDataDir, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getMagicContextStorageDir, getLegacyOpenCodeMagicContextStorageDir, sanitizeDiagnosticText, hasShareabilitySensitiveText, log, sessionLog, flushLogger };
491
+ export { setHarness, getHarness, harnessOwnsOpenCodeStore, getDataDir, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getMagicContextStorageDir, getLegacyOpenCodeMagicContextStorageDir, sanitizeDiagnosticText, hasShareabilitySensitiveText, log, sessionLog, flushLogger };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  log
3
- } from "./index-bfd52y8p.js";
3
+ } from "./index-59dmj4zs.js";
4
4
 
5
5
  // ../plugin/src/shared/safe-notification-target.ts
6
6
  var DEFAULT_TITLE_RE = /^(New session - |Child session - )\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  log
3
- } from "./index-bfd52y8p.js";
3
+ } from "./index-59dmj4zs.js";
4
4
 
5
5
  // ../plugin/src/shared/write-transaction-timing.ts
6
6
  var SLOW_WRITE_TRANSACTION_THRESHOLD_MS = 1000;