@cortexkit/pi-magic-context 0.49.6 → 0.49.8

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.
Files changed (50) hide show
  1. package/dist/auto-search-worker.js +10 -7
  2. package/dist/{compaction-marker-candidates-9w5g66at.js → compaction-marker-candidates-n4dphyz4.js} +3 -3
  3. package/dist/compaction-marker-candidates-worker.js +2 -2
  4. package/dist/embedding-backfill-chva00z3.js +20 -0
  5. package/dist/embedding-worker-process.js +6 -2
  6. package/dist/embedding-worker.js +6 -5
  7. package/dist/historian-calibration-extension.js +1 -1
  8. package/dist/{index-j7pa3t4s.js → index-18qe4gs1.js} +113 -27
  9. package/dist/{index-0j0zqb4t.js → index-3veejgp8.js} +1 -1
  10. package/dist/{index-0vrkp1jq.js → index-43zqh10z.js} +1 -1
  11. package/dist/{index-r56xgha8.js → index-4pxydwvg.js} +1 -1
  12. package/dist/{index-5rc9kvrk.js → index-4vj37yw9.js} +4 -3
  13. package/dist/{index-fcacf11g.js → index-54r5vs9w.js} +4 -4
  14. package/dist/{index-cd6bjrj4.js → index-6e3yv1jt.js} +4 -4
  15. package/dist/{index-swab4319.js → index-729kkhmf.js} +4 -3
  16. package/dist/{index-gc2749rx.js → index-8yjhda46.js} +9 -6
  17. package/dist/{index-8vbh4tzw.js → index-asrxgdt4.js} +63 -19
  18. package/dist/{index-wf7mwdnf.js → index-fdxzpnbj.js} +2 -2
  19. package/dist/{index-kamhcj15.js → index-gqxsds3q.js} +6 -3
  20. package/dist/{index-x3dcnxh0.js → index-gycf3sp7.js} +5 -1
  21. package/dist/{index-kxxdyjfs.js → index-hy44m6jc.js} +1 -1
  22. package/dist/{index-0p9gemc6.js → index-jsyjxgfy.js} +172 -36
  23. package/dist/{index-290tzwp1.js → index-kh3jt7t9.js} +1 -1
  24. package/dist/{index-hfnjfk4d.js → index-pdhbj18g.js} +71 -70
  25. package/dist/{index-fx0r5485.js → index-qc8e13wc.js} +22 -22
  26. package/dist/{index-9mn34fnx.js → index-r8cy8hmq.js} +5 -5
  27. package/dist/{index-57mvvbbh.js → index-rggtvnbg.js} +40 -29
  28. package/dist/{index-21v1kfs7.js → index-szh001qb.js} +6 -3
  29. package/dist/{index-cyrnv16r.js → index-ta0ed2nc.js} +2 -0
  30. package/dist/{index-5z1h0qsa.js → index-tdhppxwd.js} +9 -9
  31. package/dist/{index-p4matwj0.js → index-v26j81w6.js} +5 -5
  32. package/dist/{index-mcgehvgw.js → index-zzn7qbps.js} +1 -1
  33. package/dist/index.js +1071 -390
  34. package/dist/{logger-j6tecd1h.js → logger-qg51hmp7.js} +1 -1
  35. package/dist/{message-index-m6snq0fh.js → message-index-1wta074c.js} +14 -14
  36. package/dist/{message-index-bounded-8a94k72f.js → message-index-bounded-ss3ctdwb.js} +14 -14
  37. package/dist/{message-time-backfill-xqwg3hg1.js → message-time-backfill-q9s88zdv.js} +3 -3
  38. package/dist/migration-worker.js +10 -10
  39. package/dist/{project-embedding-registry-3x6nmszv.js → project-embedding-registry-bxawck58.js} +11 -11
  40. package/dist/raw-ordinal-warmup-worker.js +17 -15
  41. package/dist/{read-session-chunk-49e1ayzs.js → read-session-chunk-1jagnq05.js} +11 -9
  42. package/dist/{read-session-raw-545mgtjz.js → read-session-raw-hm7ptnrh.js} +3 -3
  43. package/dist/{safe-notification-target-vn9kpmv4.js → safe-notification-target-62ty6rvp.js} +2 -2
  44. package/dist/{search-q76dp7w9.js → search-x7cachq0.js} +21 -21
  45. package/dist/{sqlite-wp7wddw3.js → sqlite-adjpy399.js} +3 -1
  46. package/dist/{storage-memory-7417pbm9.js → storage-memory-axnsk5t1.js} +2 -2
  47. package/dist/{storage-tags-cvjsrbqh.js → storage-tags-6j5s2q49.js} +5 -5
  48. package/dist/subagent-entry.js +24 -24
  49. package/package.json +1 -1
  50. package/dist/embedding-backfill-809pgwvb.js +0 -20
@@ -1,16 +1,23 @@
1
1
  // ../plugin/src/shared/sqlite.ts
2
- import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
3
+ var resourceRoot = new AsyncResource("magic-context:root");
4
+ function inRootAsyncContext2(operation) {
5
+ return resourceRoot.runInAsyncScope(operation);
6
+ }
3
7
  var reportSlowPrivilegedWrite;
4
8
  function registerSlowWriteReporter2(reporter) {
5
9
  reportSlowPrivilegedWrite = reporter;
6
10
  }
7
11
  var sqliteDiagnosticSink;
8
- function registerSqliteDiagnosticSink2(sink) {
12
+ var sqliteDiagnosticHost = () => "unknown";
13
+ function registerSqliteDiagnosticSink2(sink, host) {
9
14
  sqliteDiagnosticSink = sink;
15
+ if (host)
16
+ sqliteDiagnosticHost = host;
10
17
  }
11
18
  function reportSqliteDiagnostic(message) {
12
19
  try {
13
- sqliteDiagnosticSink?.(`[magic-context] ${message}`);
20
+ sqliteDiagnosticSink?.(`[magic-context] ${message} pid=${process.pid} host=${sqliteDiagnosticHost()}`);
14
21
  } catch {}
15
22
  }
16
23
  function detectSqliteRuntime2() {
@@ -169,17 +176,25 @@ function installTransactionRouting(db, readonly) {
169
176
  assertTransformWrite2();
170
177
  if (/^\s*BEGIN\s+(?:IMMEDIATE|EXCLUSIVE)(?:\s+TRANSACTION)?\s*;?\s*$/i.test(sql)) {
171
178
  openWriterTransactions.delete(db);
172
- if (transformPassScope.getStore()?.active || backgroundWriterScope.getStore())
179
+ if (transformPassScope.getStore()?.active || backgroundWriterScope.getStore()) {
173
180
  acquireShort(db, () => nativeExec(sql), sql.trim());
174
- else
181
+ } else {
175
182
  nativeExec(sql);
183
+ openWriterTransactions.set(db, {
184
+ site: sql.trim(),
185
+ lane: "background",
186
+ acquireMs: 0,
187
+ attempts: 1,
188
+ acquiredAt: performance.now()
189
+ });
190
+ }
176
191
  return db;
177
192
  }
178
193
  if (WRITER_TRANSACTION_END.test(sql) && openWriterTransactions.has(db))
179
194
  return endWriterTransaction(db, () => nativeExec(sql), sql);
180
195
  if (!/^\s*(?:SELECT|EXPLAIN|PRAGMA|COMMIT|END|ROLLBACK|SAVEPOINT|RELEASE)\b/i.test(sql)) {
181
196
  try {
182
- return withAutocommitTimeout(db, () => nativeExec(sql));
197
+ return withAutocommitTimeout(db, () => nativeExec(sql), false);
183
198
  } finally {
184
199
  if (mayChangeTagIdentity(sql))
185
200
  tagIdentityWriteGeneration += 1;
@@ -321,7 +336,7 @@ function trackSqliteConnection(db, filename, options) {
321
336
  }
322
337
  var TrackedDatabase = new Proxy(DatabaseImpl, {
323
338
  construct(target, args) {
324
- const db = Reflect.construct(target, args, target);
339
+ const db = inRootAsyncContext2(() => Reflect.construct(target, args, target));
325
340
  return trackSqliteConnection(db, args[0], args[1]);
326
341
  }
327
342
  });
@@ -497,7 +512,7 @@ class SqliteAcquisitionBusyError extends Error {
497
512
  var SHORT_BUSY_TIMEOUT_MS = 25;
498
513
  var FOREGROUND_IN_PASS_BUSY_TIMEOUT_MS = 2000;
499
514
  var FOREGROUND_ACQUISITION_BUDGET_MS = 16500;
500
- var SLOW_WRITER_LOG_MS = 250;
515
+ var SLOW_WRITER_LOG_MS = 100;
501
516
  var WRITER_TRANSACTION_END = /^\s*(?:COMMIT|END|ROLLBACK)(?:\s+TRANSACTION)?\s*;?\s*$/i;
502
517
  var writerAcquisitionScope = new AsyncLocalStorage;
503
518
  var openWriterTransactions = new WeakMap;
@@ -505,25 +520,52 @@ function foregroundWaitLease() {
505
520
  const lease = transformPassScope.getStore();
506
521
  return lease?.active && !admissionScope.getStore() && !backgroundWriterScope.getStore() ? lease : undefined;
507
522
  }
508
- function withAutocommitTimeout(db, operation) {
523
+ function withAutocommitTimeout(db, operation, singleStatement = true) {
509
524
  assertTransformWrite2();
510
525
  const lease = foregroundWaitLease();
511
- if (isInTransaction(db) || !lease && !backgroundWriterScope.getStore())
526
+ if (isInTransaction(db))
512
527
  return operation();
513
- const previous = pragmaNumber(db, "busy_timeout");
514
- db.exec(`PRAGMA busy_timeout=${lease ? Math.floor(Math.min(lease.remainingWaitMs, lease.guard?.remainingMs() ?? Infinity)) : SHORT_BUSY_TIMEOUT_MS}`);
528
+ const scoped = lease || backgroundWriterScope.getStore();
529
+ const previous = scoped ? pragmaNumber(db, "busy_timeout") : null;
515
530
  const started = performance.now();
531
+ let completed = false;
532
+ const execute = () => {
533
+ const result = operation();
534
+ completed = true;
535
+ return result;
536
+ };
516
537
  try {
517
- return operation();
538
+ if (!scoped)
539
+ return execute();
540
+ if (singleStatement) {
541
+ db.exec("PRAGMA busy_timeout=0");
542
+ try {
543
+ return execute();
544
+ } catch (error) {
545
+ if (!isTransientSqliteError2(error) || isInTransaction(db))
546
+ throw error;
547
+ }
548
+ assertTransformWrite2();
549
+ }
550
+ const timeout = Math.floor(Math.min(lease?.remainingWaitMs ?? SHORT_BUSY_TIMEOUT_MS, lease?.guard?.remainingMs() ?? Infinity));
551
+ db.exec(`PRAGMA busy_timeout=${timeout}`);
552
+ const waitStarted = performance.now();
553
+ try {
554
+ return execute();
555
+ } finally {
556
+ if (lease)
557
+ lease.remainingWaitMs = Math.max(0, lease.remainingWaitMs - (performance.now() - waitStarted));
558
+ }
518
559
  } catch (error) {
519
560
  if (lease && isTransientSqliteError2(error))
520
561
  throw new SqliteAcquisitionBusyError(error, "autocommit");
521
562
  throw error;
522
563
  } finally {
523
- if (lease)
524
- lease.remainingWaitMs = Math.max(0, lease.remainingWaitMs - (performance.now() - started));
564
+ const elapsed = performance.now() - started;
525
565
  if (previous !== null)
526
566
  db.exec(`PRAGMA busy_timeout=${previous}`);
567
+ if (elapsed >= SLOW_WRITER_LOG_MS)
568
+ reportSqliteDiagnostic(`sqlite writer site=autocommit lane=${lease ? "foreground" : "background"} elapsed_ms=${Math.round(elapsed)} timing=statement_including_acquisition outcome=${completed ? "completed" : "failed"} caller=${writerCaller()}`);
527
569
  }
528
570
  }
529
571
  function acquireShort(db, acquire, site) {
@@ -569,24 +611,26 @@ function acquireShort(db, acquire, site) {
569
611
  }
570
612
  function endWriterTransaction(db, end, sql) {
571
613
  let ended = false;
572
- const endStarted = performance.now();
573
614
  try {
574
615
  const result = end();
575
616
  ended = true;
576
617
  return result;
577
618
  } finally {
578
619
  const open = openWriterTransactions.get(db);
579
- const endMs = performance.now() - endStarted;
580
620
  if (open && !isInTransaction(db)) {
581
621
  openWriterTransactions.delete(db);
582
622
  const holdMs = performance.now() - open.acquiredAt;
583
623
  if (open.acquireMs >= SLOW_WRITER_LOG_MS || holdMs >= SLOW_WRITER_LOG_MS) {
584
624
  const outcome = /^\s*ROLLBACK/i.test(sql) ? "rolled_back" : ended ? "committed" : "failed";
585
- reportSqliteDiagnostic(`sqlite writer site=${open.site} lane=${open.lane} acquire_ms=${Math.round(open.acquireMs)} hold_ms=${Math.round(holdMs)} end_ms=${Math.round(endMs)} attempts=${open.attempts} outcome=${outcome}`);
625
+ reportSqliteDiagnostic(`sqlite writer site=${open.site} lane=${open.lane} acquire_ms=${Math.round(open.acquireMs)} hold_ms=${Math.round(holdMs)} attempts=${open.attempts} outcome=${outcome} timing=through_commit_upper_bound caller=${writerCaller()}`);
586
626
  }
587
627
  }
588
628
  }
589
629
  }
630
+ function writerCaller() {
631
+ return new Error().stack?.split(`
632
+ `).find((line) => line.includes(" at ") && !/[/\\]sqlite\.[tj]s[:)]/.test(line) && !/\b(?:writerCaller|endWriterTransaction|withAutocommitTimeout|value)\b/.test(line))?.trim().replace(/\s+/g, "_") ?? "unknown";
633
+ }
590
634
  async function beginSqliteWriterAsync2(db, site) {
591
635
  const started = performance.now();
592
636
  let attempts = 0;
@@ -777,4 +821,4 @@ async function yieldIndexChunk2() {
777
821
  await yieldIndexTurn();
778
822
  }
779
823
 
780
- export { registerSlowWriteReporter2, registerSqliteDiagnosticSink2, detectSqliteRuntime2, getTagIdentityWriteGeneration2, Database2, getSqliteDatabasePath2, prepareCachedStatement2, withSqliteBackgroundWriter2, withSqliteTransformPass2, withoutSqliteTransformPass2, guardSqliteTransformPass2, assertTransformWrite2, isTransientSqliteError2, beginSqliteWriterAsync2, withAsyncPrivilegedWriter2, withPrivilegedWriter2, indexCoordinationInput2, releaseIndexOwner2, withIndexChunk2, yieldIndexChunk2 };
824
+ export { inRootAsyncContext2, registerSlowWriteReporter2, registerSqliteDiagnosticSink2, detectSqliteRuntime2, getTagIdentityWriteGeneration2, Database2, getSqliteDatabasePath2, prepareCachedStatement2, withSqliteBackgroundWriter2, withSqliteTransformPass2, withoutSqliteTransformPass2, guardSqliteTransformPass2, assertTransformWrite2, isTransientSqliteError2, beginSqliteWriterAsync2, withAsyncPrivilegedWriter2, withPrivilegedWriter2, indexCoordinationInput2, releaseIndexOwner2, withIndexChunk2, yieldIndexChunk2 };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  withSqliteBackgroundWriter2,
3
3
  withoutSqliteTransformPass2
4
- } from "./index-8vbh4tzw.js";
4
+ } from "./index-asrxgdt4.js";
5
5
  import {
6
6
  logSlowWriteTransaction
7
- } from "./index-0vrkp1jq.js";
7
+ } from "./index-43zqh10z.js";
8
8
 
9
9
  // ../plugin/src/shared/project-directory-key.ts
10
10
  import path from "node:path";
@@ -1,10 +1,13 @@
1
1
  import {
2
2
  getMagicContextStorageDir,
3
3
  log2
4
- } from "./index-x3dcnxh0.js";
4
+ } from "./index-gycf3sp7.js";
5
+ import {
6
+ inRootAsyncContext2
7
+ } from "./index-asrxgdt4.js";
5
8
  import {
6
9
  projectDirectoryKey
7
- } from "./index-wf7mwdnf.js";
10
+ } from "./index-fdxzpnbj.js";
8
11
  import {
9
12
  writeStorageFileAtomicSync
10
13
  } from "./index-81nthk8j.js";
@@ -496,7 +499,7 @@ function bootQuietRemainingMs(now = Date.now()) {
496
499
  return Math.max(0, bootQuietUntilMs - now);
497
500
  }
498
501
  function scheduleAfterBootQuiet(task, additionalDelayMs = 0) {
499
- const timer = setTimeout(task, bootQuietRemainingMs() + Math.max(0, additionalDelayMs));
502
+ const timer = inRootAsyncContext2(() => setTimeout(task, bootQuietRemainingMs() + Math.max(0, additionalDelayMs)));
500
503
  timer.unref?.();
501
504
  return timer;
502
505
  }
@@ -219,7 +219,7 @@ var SECRET_TEXT_PATTERNS = [
219
219
  replacement: "<GITHUB_PAT_REDACTED>"
220
220
  },
221
221
  {
222
- pattern: /\b(?:gh[opsu]|ghr)_[A-Za-z0-9]{30,}/g,
222
+ pattern: /\b(?:gh[opsu]|ghr)_[A-Za-z0-9_-]{30,}/g,
223
223
  replacement: "<GITHUB_TOKEN_REDACTED>"
224
224
  },
225
225
  {
@@ -250,6 +250,10 @@ var SECRET_TEXT_PATTERNS = [
250
250
  pattern: /\b((?:x-)?(?:api-?key|api-?token|auth-?token|access-?token)\s*:\s*)([^\s'"`,;<>]{6,})/gi,
251
251
  replacement: (full, prefix, value) => isNonSecretScalarValue(value) ? full : `${prefix}<REDACTED:api_key>`
252
252
  },
253
+ {
254
+ pattern: /\b((?:api[_-]?key|client[_-]?secret|access[_-]?token|token|secret|password|passwd|pwd)\s*:\s*)([^\s'"`,;<>]{6,})/gi,
255
+ replacement: (full, prefix, value) => isNonSecretScalarValue(value) ? full : `${prefix}<REDACTED:credential>`
256
+ },
253
257
  {
254
258
  pattern: /\b([a-z][a-z0-9+.-]*:\/\/[^\s/:@]+:)([^\s/@]+)(@)/gi,
255
259
  replacement: (_full, prefix, _password, at) => `${prefix}<REDACTED:password>${at}`
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  withPrivilegedWriter2
3
- } from "./index-8vbh4tzw.js";
3
+ } from "./index-asrxgdt4.js";
4
4
  import {
5
5
  MEMORY_CATEGORY_ORDER_SQL
6
6
  } from "./index-135e8hvg.js";