@cortexkit/pi-magic-context 0.49.7 → 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 +6 -6
  2. package/dist/{compaction-marker-candidates-tqcq5n00.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-fhv6ydkq.js → index-18qe4gs1.js} +18 -11
  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-7mm27xdc.js → index-4vj37yw9.js} +4 -3
  13. package/dist/{index-6vjj0555.js → index-54r5vs9w.js} +4 -4
  14. package/dist/{index-8ye22z7k.js → index-6e3yv1jt.js} +4 -4
  15. package/dist/{index-dj8hpkz7.js → index-729kkhmf.js} +4 -3
  16. package/dist/{index-gc2749rx.js → index-8yjhda46.js} +9 -6
  17. package/dist/{index-7ptxvfc5.js → index-asrxgdt4.js} +33 -10
  18. package/dist/{index-34zacc0h.js → index-fdxzpnbj.js} +2 -2
  19. package/dist/{index-gqsfhksw.js → index-gqxsds3q.js} +6 -3
  20. package/dist/{index-x3dcnxh0.js → index-gycf3sp7.js} +5 -1
  21. package/dist/{index-dj784nyr.js → index-hy44m6jc.js} +1 -1
  22. package/dist/{index-mrsarsbh.js → index-jsyjxgfy.js} +25 -24
  23. package/dist/{index-290tzwp1.js → index-kh3jt7t9.js} +1 -1
  24. package/dist/{index-8jpqq2yk.js → index-pdhbj18g.js} +14 -13
  25. package/dist/{index-0d8zqccx.js → index-qc8e13wc.js} +22 -22
  26. package/dist/{index-0eg59y8d.js → index-r8cy8hmq.js} +5 -5
  27. package/dist/{index-6q5mx0cz.js → index-rggtvnbg.js} +38 -28
  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-0ww9cgfd.js → index-tdhppxwd.js} +9 -9
  31. package/dist/{index-a7fj661j.js → index-v26j81w6.js} +5 -5
  32. package/dist/{index-mcgehvgw.js → index-zzn7qbps.js} +1 -1
  33. package/dist/index.js +109 -86
  34. package/dist/{logger-j6tecd1h.js → logger-qg51hmp7.js} +1 -1
  35. package/dist/{message-index-8rxj3cxh.js → message-index-1wta074c.js} +14 -14
  36. package/dist/{message-index-bounded-e5bv8gzm.js → message-index-bounded-ss3ctdwb.js} +14 -14
  37. package/dist/{message-time-backfill-hmekd2jj.js → message-time-backfill-q9s88zdv.js} +3 -3
  38. package/dist/migration-worker.js +10 -10
  39. package/dist/{project-embedding-registry-z5m4eh3d.js → project-embedding-registry-bxawck58.js} +11 -11
  40. package/dist/raw-ordinal-warmup-worker.js +6 -6
  41. package/dist/{read-session-chunk-sp5adk01.js → read-session-chunk-1jagnq05.js} +9 -9
  42. package/dist/{read-session-raw-s14c7nf3.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-hgfaqytc.js → search-x7cachq0.js} +21 -21
  45. package/dist/{sqlite-f8kh2n10.js → sqlite-adjpy399.js} +3 -1
  46. package/dist/{storage-memory-yf7r98vz.js → storage-memory-axnsk5t1.js} +2 -2
  47. package/dist/{storage-tags-0xk95neb.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-vygvr2x4.js +0 -20
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  log2,
16
16
  sessionLog2,
17
17
  flushLogger2
18
- } from "./index-x3dcnxh0.js";
18
+ } from "./index-gycf3sp7.js";
19
19
  import {
20
20
  COMPACTION_ENABLED_PATH,
21
21
  isDreamerRunnable,
@@ -250,7 +250,7 @@ import {
250
250
  registerTodoStateLifecycle,
251
251
  syncCtxMemoryToolEnabled,
252
252
  registerMagicContextTools
253
- } from "./index-mrsarsbh.js";
253
+ } from "./index-jsyjxgfy.js";
254
254
  import {
255
255
  canonicalModelIdentity,
256
256
  piModelRefToCanonical,
@@ -267,7 +267,7 @@ import {
267
267
  DEFAULT_HISTORIAN_TIMEOUT_MS,
268
268
  DREAM_TASK_PROMOTION_DEFAULTS,
269
269
  LIVE_RELOAD_CONFIG_PATHS
270
- } from "./index-cyrnv16r.js";
270
+ } from "./index-ta0ed2nc.js";
271
271
  import {
272
272
  FAIL_CLOSED_DOCTOR_COMMAND,
273
273
  formatFailClosedBlockingMessage,
@@ -290,7 +290,7 @@ import {
290
290
  openCurrentDatabase,
291
291
  openDatabaseAsync,
292
292
  closeDatabase
293
- } from "./index-6q5mx0cz.js";
293
+ } from "./index-rggtvnbg.js";
294
294
  import {
295
295
  setHomeProjectPermission,
296
296
  ProjectIdentityError,
@@ -301,7 +301,7 @@ import {
301
301
  resolveProjectIdentityForSession,
302
302
  beginBootQuietPeriod,
303
303
  scheduleAfterBootQuiet
304
- } from "./index-gqsfhksw.js";
304
+ } from "./index-gqxsds3q.js";
305
305
  import {
306
306
  detectThinkingBindingMismatch,
307
307
  detectLatestTurnThinkingMismatch,
@@ -440,6 +440,7 @@ import {
440
440
  opaqueThinkingCost,
441
441
  SKELETON_REAL_INPUT_MAX_BYTES,
442
442
  toolInputStringBytes,
443
+ hasRawMessageProvider2,
443
444
  setRawMessageProvider2,
444
445
  withRawMessageProvider2,
445
446
  cleanUserText2,
@@ -458,7 +459,7 @@ import {
458
459
  getRawSessionTagKeysThrough2,
459
460
  getLegacyProtectedTailStartOrdinal2,
460
461
  readSessionChunk2
461
- } from "./index-fhv6ydkq.js";
462
+ } from "./index-18qe4gs1.js";
462
463
  import {
463
464
  UNKNOWN_FIT_RATIO,
464
465
  hasMeasuredDecisionCalibration,
@@ -541,7 +542,7 @@ import {
541
542
  getToolTagNumberByOwner2,
542
543
  getNullOwnerToolTag2,
543
544
  adoptNullOwnerToolTag2
544
- } from "./index-6vjj0555.js";
545
+ } from "./index-54r5vs9w.js";
545
546
  import {
546
547
  textMentionsRecentCommit,
547
548
  hasMeaningfulUserText2,
@@ -553,8 +554,9 @@ import {
553
554
  estimateTokens,
554
555
  estimateFixedPromptTokens,
555
556
  normalizeText
556
- } from "./index-r56xgha8.js";
557
+ } from "./index-4pxydwvg.js";
557
558
  import {
559
+ inRootAsyncContext2,
558
560
  Database2,
559
561
  getSqliteDatabasePath2,
560
562
  withSqliteBackgroundWriter2,
@@ -565,7 +567,7 @@ import {
565
567
  isTransientSqliteError2,
566
568
  withAsyncPrivilegedWriter2,
567
569
  indexCoordinationInput2
568
- } from "./index-7ptxvfc5.js";
570
+ } from "./index-asrxgdt4.js";
569
571
  import {
570
572
  stableStringify,
571
573
  closeQuietly,
@@ -577,7 +579,7 @@ import {
577
579
  tagRevisionKey,
578
580
  tagIdentityRevisionKey,
579
581
  TAG_INSERT_CONFLICT_ROWS
580
- } from "./index-mcgehvgw.js";
582
+ } from "./index-zzn7qbps.js";
581
583
  import {
582
584
  resolveOpenCodeDbPath,
583
585
  assertOpenCodeStoreGeneration,
@@ -590,10 +592,10 @@ import"./index-399p688g.js";
590
592
  import {
591
593
  runSessionWarmupWorker,
592
594
  RAW_SUMMARY_TEXT_MAX_CHARS2
593
- } from "./index-7mm27xdc.js";
595
+ } from "./index-4vj37yw9.js";
594
596
  import {
595
597
  piHarnessKindFromExecutable
596
- } from "./index-0j0zqb4t.js";
598
+ } from "./index-3veejgp8.js";
597
599
  import {
598
600
  BoundedSessionMap,
599
601
  LkgRecoveryFenceError,
@@ -616,13 +618,13 @@ import {
616
618
  indexSingleMessage2,
617
619
  indexMessagesAfterOrdinal2,
618
620
  sweepOrphanedOpenCodeMessageIndexes2
619
- } from "./index-0ww9cgfd.js";
621
+ } from "./index-tdhppxwd.js";
620
622
  import {
621
623
  formatSynapseLaneDescriptor
622
- } from "./index-21v1kfs7.js";
624
+ } from "./index-szh001qb.js";
623
625
  import {
624
626
  sameProjectDirectory
625
- } from "./index-34zacc0h.js";
627
+ } from "./index-fdxzpnbj.js";
626
628
  import {
627
629
  buildCanonicalChunkTextFromFts,
628
630
  buildCompartmentSummaryFallbackText,
@@ -632,7 +634,7 @@ import {
632
634
  replaceCompartmentChunkEmbeddings,
633
635
  deleteChunkEmbedBackoffForSession,
634
636
  chunkWindowSourceKey
635
- } from "./index-8ye22z7k.js";
637
+ } from "./index-6e3yv1jt.js";
636
638
  import {
637
639
  recordSessionProjectIdentity,
638
640
  GIT_SWEEP_LEASE_RENEWAL_MS,
@@ -657,7 +659,7 @@ import {
657
659
  embedSessionCompartmentChunks2,
658
660
  getEmbeddingCoverageStatus2,
659
661
  getAutoEmbeddingSessionCoverage2
660
- } from "./index-0d8zqccx.js";
662
+ } from "./index-qc8e13wc.js";
661
663
  import {
662
664
  V2_MEMORY_CATEGORIES
663
665
  } from "./index-135e8hvg.js";
@@ -669,7 +671,7 @@ import {
669
671
  expandWorkspaceIdentitySetWithAliases,
670
672
  sourceNameForMemory,
671
673
  computeWorkspaceEpochFingerprint
672
- } from "./index-0eg59y8d.js";
674
+ } from "./index-r8cy8hmq.js";
673
675
  import {
674
676
  configureContextDatabasePragmas2
675
677
  } from "./index-fapenpch.js";
@@ -719,7 +721,7 @@ import {
719
721
  normalizeVerificationFiles,
720
722
  indexCommitsForProject,
721
723
  embedUnembeddedCommits
722
- } from "./index-8jpqq2yk.js";
724
+ } from "./index-pdhbj18g.js";
723
725
  import {
724
726
  setEmbeddingSessionBusy2,
725
727
  isEmbeddingHostBusy2
@@ -743,18 +745,18 @@ import {
743
745
  setMemoryClassification2,
744
746
  archiveMemory2,
745
747
  getMemoryCountsByStatus2
746
- } from "./index-dj784nyr.js";
748
+ } from "./index-hy44m6jc.js";
747
749
  import {
748
750
  invalidateMemory2
749
751
  } from "./index-yhzhdp3m.js";
750
752
  import {
751
753
  pushNotification2
752
754
  } from "./index-q1yc6bs0.js";
753
- import"./index-gc2749rx.js";
755
+ import"./index-8yjhda46.js";
754
756
  import {
755
757
  cosineSimilarity
756
- } from "./index-a7fj661j.js";
757
- import"./index-dj8hpkz7.js";
758
+ } from "./index-v26j81w6.js";
759
+ import"./index-729kkhmf.js";
758
760
  import {
759
761
  buildHiddenAgentRegistrations,
760
762
  logTemperatureDecision,
@@ -762,7 +764,7 @@ import {
762
764
  SubagentTelemetry,
763
765
  readHostSystemPrompt
764
766
  } from "./index-zh1jw8qp.js";
765
- import"./index-290tzwp1.js";
767
+ import"./index-kh3jt7t9.js";
766
768
  import {
767
769
  __toESM
768
770
  } from "./index-22jkk6wg.js";
@@ -775,7 +777,7 @@ import {
775
777
  import {
776
778
  logSlowWriteTransaction,
777
779
  WriteTransactionSteps
778
- } from "./index-0vrkp1jq.js";
780
+ } from "./index-43zqh10z.js";
779
781
  import {
780
782
  setStoragePrivatePermissionEnforcement,
781
783
  ensureStorageDirectorySync,
@@ -3330,7 +3332,7 @@ function createNodeHostStallProfiler(deps) {
3330
3332
  if (stopped || !existsSync5(enablePath))
3331
3333
  return;
3332
3334
  session = api;
3333
- api.connect();
3335
+ inRootAsyncContext2(() => api.connect());
3334
3336
  await post(api, "Profiler.enable");
3335
3337
  await post(api, "Profiler.setSamplingInterval", {
3336
3338
  interval: Math.round(options.sampleIntervalMs * 1000)
@@ -3380,7 +3382,6 @@ function createNodeHostStallProfiler(deps) {
3380
3382
  isUnavailable: () => unavailable
3381
3383
  };
3382
3384
  }
3383
-
3384
3385
  // ../plugin/src/shared/host-stall-profiler.ts
3385
3386
  function hostStallProfilerDir() {
3386
3387
  return path7.join(getMagicContextStorageDir(), HOST_PROFILER_DIRNAME);
@@ -3397,7 +3398,7 @@ function startHostStallProfilerSwitch() {
3397
3398
  now: () => performance.now(),
3398
3399
  wallNow: () => Date.now(),
3399
3400
  setInterval: (callback, ms) => {
3400
- const handle = setInterval(callback, ms);
3401
+ const handle = inRootAsyncContext2(() => setInterval(callback, ms));
3401
3402
  handle.unref?.();
3402
3403
  return handle;
3403
3404
  },
@@ -3424,7 +3425,7 @@ function startHostStallProfilerSwitch() {
3424
3425
  // package.json
3425
3426
  var package_default = {
3426
3427
  name: "@cortexkit/pi-magic-context",
3427
- version: "0.49.7",
3428
+ version: "0.49.8",
3428
3429
  type: "module",
3429
3430
  description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
3430
3431
  main: "dist/index.js",
@@ -9697,7 +9698,7 @@ function startLeaseHeartbeat(db, holderId, leaseKey, onLost, intervalOrAcquisiti
9697
9698
  }
9698
9699
  };
9699
9700
  beat();
9700
- const timer = lost ? undefined : setInterval(() => withSqliteBackgroundWriter2(beat), intervalMs);
9701
+ const timer = lost ? undefined : inRootAsyncContext2(() => setInterval(() => withSqliteBackgroundWriter2(beat), intervalMs));
9701
9702
  return {
9702
9703
  stop: () => {
9703
9704
  if (timer)
@@ -18626,10 +18627,10 @@ async function sourceReady(source, sessionId) {
18626
18627
  function defer(fn) {
18627
18628
  const immediate = globalThis.setImmediate;
18628
18629
  if (typeof immediate === "function") {
18629
- immediate(fn);
18630
+ inRootAsyncContext2(() => immediate(fn));
18630
18631
  return;
18631
18632
  }
18632
- setTimeout(fn, 0);
18633
+ inRootAsyncContext2(() => setTimeout(fn, 0));
18633
18634
  }
18634
18635
  function yieldToEventLoop() {
18635
18636
  return new Promise((resolve) => defer(resolve));
@@ -18706,14 +18707,14 @@ function scheduleReconciliation(db, sessionId, readMessages) {
18706
18707
  reconcileSessionIndex(db, sessionId, readMessages).then((ran) => {
18707
18708
  if (ran)
18708
18709
  return;
18709
- setTimeout(() => {
18710
+ inRootAsyncContext2(() => setTimeout(() => {
18710
18711
  heapHolder.reconciliationScheduledSessions.delete(sessionId);
18711
18712
  scheduleReconciliation(db, sessionId, readMessages);
18712
- }, PREPARE_RETRY_MS).unref?.();
18713
+ }, PREPARE_RETRY_MS)).unref?.();
18713
18714
  }).catch((error) => {
18714
18715
  logIndexingError(sessionId, "reconciliation", error);
18715
18716
  if (isDatabaseLockedError(error))
18716
- setTimeout(() => scheduleReconciliation(db, sessionId, readMessages), 1000).unref();
18717
+ inRootAsyncContext2(() => setTimeout(() => scheduleReconciliation(db, sessionId, readMessages), 1000)).unref();
18717
18718
  }).finally(() => {
18718
18719
  heapHolder.reconciliationScheduledSessions.delete(sessionId);
18719
18720
  });
@@ -18728,7 +18729,7 @@ function scheduleIncrementalIndex(db, sessionId, messageId, messageSource) {
18728
18729
  const activeTimer = heapHolder.incrementalTimers.get(schedulingKey);
18729
18730
  if (activeTimer)
18730
18731
  clearTimeout(activeTimer);
18731
- const timer = setTimeout(() => {
18732
+ const timer = inRootAsyncContext2(() => setTimeout(() => {
18732
18733
  heapHolder.incrementalTimers.delete(schedulingKey);
18733
18734
  heapHolder.pendingIncrementalKeys.add(schedulingKey);
18734
18735
  const indexMessage = async () => {
@@ -18772,7 +18773,7 @@ function scheduleIncrementalIndex(db, sessionId, messageId, messageSource) {
18772
18773
  if ((sessionEpochs.get(sessionId) ?? 0) === epoch)
18773
18774
  heapHolder.pendingIncrementalKeys.delete(schedulingKey);
18774
18775
  });
18775
- }, INCREMENTAL_DEBOUNCE_MS);
18776
+ }, INCREMENTAL_DEBOUNCE_MS));
18776
18777
  heapHolder.incrementalTimers.set(schedulingKey, timer);
18777
18778
  }
18778
18779
  async function indexSingleMessageOffThread(db, sessionId, message) {
@@ -18946,7 +18947,7 @@ async function startDreamScheduleTimer(args) {
18946
18947
  startupTickTimer = null;
18947
18948
  runTick("startup");
18948
18949
  });
18949
- const timer = setInterval(() => runTick("interval"), DREAM_TIMER_INTERVAL_MS);
18950
+ const timer = inRootAsyncContext2(() => setInterval(() => runTick("interval"), DREAM_TIMER_INTERVAL_MS));
18950
18951
  if (typeof timer === "object" && "unref" in timer) {
18951
18952
  timer.unref();
18952
18953
  }
@@ -19242,7 +19243,7 @@ async function runCompiledSmartNoteSweep(reg, db) {
19242
19243
  }
19243
19244
  }
19244
19245
  function startGitSweepLeaseRenewal(db, projectIdentity, holderId) {
19245
- const timer = setInterval(() => {
19246
+ const timer = inRootAsyncContext2(() => setInterval(() => {
19246
19247
  try {
19247
19248
  if (!renewGitSweepLease(db, projectIdentity, holderId)) {
19248
19249
  log2(`[git-commits] sweep lease renewal failed for ${projectIdentity}`);
@@ -19250,7 +19251,7 @@ function startGitSweepLeaseRenewal(db, projectIdentity, holderId) {
19250
19251
  } catch (error) {
19251
19252
  log2(`[git-commits] sweep lease renewal errored for ${projectIdentity}: ${error instanceof Error ? error.message : String(error)}`);
19252
19253
  }
19253
- }, GIT_SWEEP_LEASE_RENEWAL_MS);
19254
+ }, GIT_SWEEP_LEASE_RENEWAL_MS));
19254
19255
  timer.unref?.();
19255
19256
  return () => clearInterval(timer);
19256
19257
  }
@@ -20176,7 +20177,7 @@ class PiSubagentRunner {
20176
20177
  const parentEnv = { ...process.env };
20177
20178
  delete parentEnv.MAGIC_CONTEXT_HISTORIAN_TEMPERATURE;
20178
20179
  try {
20179
- child = this.spawnImpl(this.invocation.command, [...this.invocation.prefixArgs, ...this.extraArgs, ...args], {
20180
+ child = inRootAsyncContext2(() => this.spawnImpl(this.invocation.command, [...this.invocation.prefixArgs, ...this.extraArgs, ...args], {
20180
20181
  windowsHide: true,
20181
20182
  cwd: options.cwd,
20182
20183
  env: {
@@ -20197,7 +20198,7 @@ class PiSubagentRunner {
20197
20198
  "pipe",
20198
20199
  "pipe"
20199
20200
  ]
20200
- });
20201
+ }));
20201
20202
  } catch (error) {
20202
20203
  cleanupSystemPromptFile();
20203
20204
  settle({
@@ -23402,7 +23403,7 @@ function schedulePiTransformDecisionResolve(args) {
23402
23403
  return false;
23403
23404
  pendingPiDecisionBySession.delete(args.sessionId);
23404
23405
  const token = addScheduledWriteToken(args.sessionId);
23405
- setTimeout(() => {
23406
+ inRootAsyncContext2(() => setTimeout(() => {
23406
23407
  try {
23407
23408
  if (!hasScheduledWriteToken(args.sessionId, token))
23408
23409
  return;
@@ -23422,7 +23423,7 @@ function schedulePiTransformDecisionResolve(args) {
23422
23423
  } finally {
23423
23424
  deleteScheduledWriteToken(args.sessionId, token);
23424
23425
  }
23425
- }, 0);
23426
+ }, 0));
23426
23427
  return true;
23427
23428
  }
23428
23429
  function addScheduledWriteToken(sessionId) {
@@ -26994,7 +26995,7 @@ function queueAutoSearchBackfill(db, sessionId, projectPath, query) {
26994
26995
  pending.delete(key);
26995
26996
  resolve();
26996
26997
  };
26997
- const queued = setTimeout(() => {
26998
+ const queued = inRootAsyncContext2(() => setTimeout(() => {
26998
26999
  lifecycle.signal.removeEventListener("abort", cancel);
26999
27000
  if (lifecycle.signal.aborted)
27000
27001
  return done();
@@ -27005,7 +27006,7 @@ function queueAutoSearchBackfill(db, sessionId, projectPath, query) {
27005
27006
  clearTimeout(timeout);
27006
27007
  done();
27007
27008
  });
27008
- }, 0);
27009
+ }, 0));
27009
27010
  const cancel = () => {
27010
27011
  clearTimeout(queued);
27011
27012
  done();
@@ -27052,7 +27053,7 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
27052
27053
  deadlineUnixMs: autoSearchDeadlineUnixMs(deadlineSignal)
27053
27054
  };
27054
27055
  return new Promise((resolve, reject) => {
27055
- const worker = new Worker(entry, { workerData: input });
27056
+ const worker = inRootAsyncContext2(() => new Worker(entry, { workerData: input }));
27056
27057
  let settled = false;
27057
27058
  const finish = (results, error) => {
27058
27059
  if (settled)
@@ -30788,6 +30789,7 @@ Historian pass ${passCount + 1}, attempt ${passAttempt} started for messages ${c
30788
30789
  sequenceOffset: candidateCompartments.length,
30789
30790
  dumpLabelBase: `recomp-${sessionId}-${chunk.startIndex}-${chunk.endIndex}-pass-${passCount + 1}`,
30790
30791
  timeoutMs: historianTimeoutMs,
30792
+ maxOutputTokens: deps.historianMaxOutputTokens,
30791
30793
  model: deps.model,
30792
30794
  fallbackModelId: deps.fallbackModelId,
30793
30795
  fallbackModels: deps.fallbackModels,
@@ -31302,7 +31304,6 @@ ${renderUserFacingFailure("recomp_unavailable")}`;
31302
31304
  }
31303
31305
  }
31304
31306
  }
31305
-
31306
31307
  // ../plugin/src/hooks/magic-context/compartment-runner.ts
31307
31308
  var activeRuns = new Map;
31308
31309
  function getActiveCompartmentRun(sessionId) {
@@ -31323,7 +31324,7 @@ function withPublishedCallback(deps) {
31323
31324
  };
31324
31325
  }
31325
31326
  function startLeaseRenewal(deps, holderId) {
31326
- return setInterval(() => {
31327
+ return inRootAsyncContext2(() => setInterval(() => {
31327
31328
  try {
31328
31329
  if (!renewCompartmentLease(deps.db, deps.sessionId, holderId)) {
31329
31330
  sessionLog2(deps.sessionId, "compartment lease renewal failed; publish will be skipped if holder is stale");
@@ -31331,7 +31332,7 @@ function startLeaseRenewal(deps, holderId) {
31331
31332
  } catch (err) {
31332
31333
  sessionLog2(deps.sessionId, `compartment lease renewal threw; publish will be skipped if holder is stale (${err instanceof Error ? err.message : String(err)})`);
31333
31334
  }
31334
- }, COMPARTMENT_LEASE_RENEWAL_MS);
31335
+ }, COMPARTMENT_LEASE_RENEWAL_MS));
31335
31336
  }
31336
31337
  async function executeContextRecompWithResult(deps, options = {}) {
31337
31338
  const { sessionId } = deps;
@@ -31563,6 +31564,29 @@ function trimPiMessagesToBoundary(piMessages, entryIds, cutoffMessageId, trimMut
31563
31564
  break;
31564
31565
  }
31565
31566
  }
31567
+ if (cutoffIndex < 0 && sessionId && hasRawMessageProvider2(sessionId)) {
31568
+ try {
31569
+ const branch = readRawSessionMessages2(sessionId);
31570
+ const positions = new Map(branch.map((message, index) => [message.id, index]));
31571
+ const boundaryPosition = positions.get(cutoffMessageId);
31572
+ if (boundaryPosition === undefined)
31573
+ return 0;
31574
+ let previous = -1;
31575
+ for (const [index, message] of piMessages.entries()) {
31576
+ if (isPiSystemEntry(message))
31577
+ continue;
31578
+ const id = resolveStableId(message, index, entryIds);
31579
+ const position = positions.get(id) ?? positions.get(`${SYNTH_USER_ID_PREFIX}${id}`);
31580
+ if (position === undefined || position <= previous)
31581
+ return 0;
31582
+ previous = position;
31583
+ if (position <= boundaryPosition)
31584
+ cutoffIndex = index;
31585
+ }
31586
+ } catch {
31587
+ return 0;
31588
+ }
31589
+ }
31566
31590
  if (cutoffIndex < 0)
31567
31591
  return 0;
31568
31592
  const remove = new Set;
@@ -33425,9 +33449,9 @@ class PiContextBudget {
33425
33449
  elapsed() {
33426
33450
  return this.now() - this.startedAt;
33427
33451
  }
33428
- remainingWork() {
33452
+ remainingWork = () => {
33429
33453
  return Math.max(0, PI_CONTEXT_BUDGET.workMs - this.elapsed());
33430
- }
33454
+ };
33431
33455
  remainingOutcome = () => Math.max(0, PI_CONTEXT_BUDGET.outcomeMs - this.elapsed());
33432
33456
  writerAllowance() {
33433
33457
  return Math.max(0, Math.min(PI_CONTEXT_BUDGET.writerMs, this.remainingWork() - PI_CONTEXT_BUDGET.completionReserveMs));
@@ -37152,7 +37176,7 @@ function flushPiServedArrayLedger() {
37152
37176
  function scheduleFlush() {
37153
37177
  if (flushTimer)
37154
37178
  return;
37155
- flushTimer = setTimeout(flushPiServedArrayLedger, FLUSH_DELAY_MS);
37179
+ flushTimer = inRootAsyncContext2(() => setTimeout(flushPiServedArrayLedger, FLUSH_DELAY_MS));
37156
37180
  flushTimer.unref?.();
37157
37181
  }
37158
37182
  function enqueue(filePath, line, assertCurrentPass) {
@@ -41627,7 +41651,7 @@ function registerPiContextHandler(pi, baseOptions) {
41627
41651
  const passGuard = { assert: assertCurrentPass, wait: guardAwait };
41628
41652
  guardSqliteTransformPass2({
41629
41653
  assert: assertCurrentPass,
41630
- remainingMs: () => budget.remainingWork()
41654
+ remainingMs: budget.remainingWork
41631
41655
  });
41632
41656
  budget.stage = "schema";
41633
41657
  const toolWireSchema = await guardAwait(loadPiToolWireSchema());
@@ -42268,7 +42292,7 @@ function registerPiContextHandler(pi, baseOptions) {
42268
42292
  if (historian && !options.compactionOff && budget.remainingWork() > 0) {
42269
42293
  guardSqliteTransformPass2({
42270
42294
  assert: budget.assert,
42271
- remainingMs: () => budget.remainingWork()
42295
+ remainingMs: budget.remainingWork
42272
42296
  });
42273
42297
  try {
42274
42298
  budget.assert();
@@ -42348,7 +42372,7 @@ function registerPiContextHandler(pi, baseOptions) {
42348
42372
  if (options.autoSearch?.enabled && !options.compactionOff && result.prefixMutationAllowed && budget.remainingWork() > PI_CONTEXT_BUDGET.searchMs) {
42349
42373
  guardSqliteTransformPass2({
42350
42374
  assert: budget.assert,
42351
- remainingMs: () => budget.remainingWork()
42375
+ remainingMs: budget.remainingWork
42352
42376
  });
42353
42377
  try {
42354
42378
  outputMessages = await guardAwait(runAutoSearchHintForPi({
@@ -42758,7 +42782,7 @@ function registerPiContextHandler(pi, baseOptions) {
42758
42782
  budget.assertOutcome();
42759
42783
  guardSqliteTransformPass2({
42760
42784
  assert: budget.assertOutcome,
42761
- remainingMs: () => Math.max(0, PI_CONTEXT_BUDGET.outcomeMs - budget.elapsed())
42785
+ remainingMs: budget.remainingOutcome
42762
42786
  });
42763
42787
  if (!budget.sideTurn && !lkgCompactionOff && lkgPassSnapshot && (rawMessageCount > 0 || result.servedTagNumbers?.size)) {
42764
42788
  let hostEnvelopeSignature;
@@ -43027,7 +43051,7 @@ function resolveHistoryBudgetTokensForPi(args) {
43027
43051
  }) / 100) * historyBudgetPercentage);
43028
43052
  }
43029
43053
  function startPiCompartmentLeaseRenewal(db, sessionId, holderId) {
43030
- return setInterval(() => {
43054
+ return inRootAsyncContext2(() => setInterval(() => {
43031
43055
  try {
43032
43056
  if (!renewCompartmentLease(db, sessionId, holderId)) {
43033
43057
  sessionLog2(sessionId, "compartment lease renewal failed; publish will be skipped if holder is stale");
@@ -43035,7 +43059,7 @@ function startPiCompartmentLeaseRenewal(db, sessionId, holderId) {
43035
43059
  } catch (err) {
43036
43060
  sessionLog2(sessionId, `compartment lease renewal threw; publish will be skipped if holder is stale (${err instanceof Error ? err.message : String(err)})`);
43037
43061
  }
43038
- }, COMPARTMENT_LEASE_RENEWAL_MS);
43062
+ }, COMPARTMENT_LEASE_RENEWAL_MS));
43039
43063
  }
43040
43064
  function ensureRunnablePiBoundaryForTests(snapshot) {
43041
43065
  if (true) {
@@ -43095,7 +43119,7 @@ function spawnPiHistorianRun(args) {
43095
43119
  const holderId = crypto3.randomUUID();
43096
43120
  const controller = new AbortController;
43097
43121
  historianAbortControllers.set(sessionId, controller);
43098
- const runPromise = withoutSqliteTransformPass2(() => (async () => {
43122
+ const runPromise = inRootAsyncContext2(() => (async () => {
43099
43123
  await new Promise((resolve) => setTimeout(resolve, 0));
43100
43124
  if (controller.signal.aborted)
43101
43125
  return;
@@ -45246,6 +45270,7 @@ function createPiHistorianClient(args) {
45246
45270
  model: modelOverride?.model ?? args.model,
45247
45271
  fallbackModels: modelOverride ? undefined : args.fallbackModels,
45248
45272
  timeoutMs: args.timeoutMs,
45273
+ maxOutputTokens: args.maxOutputTokens,
45249
45274
  cwd: args.directory,
45250
45275
  thinkingLevel: modelOverride ? modelOverride.qualifier : args.thinkingLevel,
45251
45276
  accountingSessionId: args.accountingSessionId,
@@ -45660,6 +45685,7 @@ Recomp started. Rebuilding the compressed history from raw session history now;
45660
45685
  systemPrompt: withContentLanguageDirective(COMPARTMENT_STRUCTURAL_SYSTEM_PROMPT, currentDeps.language, { preserveUserQuotes: true }),
45661
45686
  fallbackModels: currentDeps.historianFallbacks,
45662
45687
  timeoutMs: currentDeps.historianTimeoutMs,
45688
+ maxOutputTokens: currentDeps.historianMaxOutputTokens,
45663
45689
  thinkingLevel: currentDeps.historianThinkingLevel,
45664
45690
  directory: cwd,
45665
45691
  accountingSessionId: sessionId,
@@ -46885,14 +46911,14 @@ class StatusDialogComponent {
46885
46911
  this.detailRefresh = new PiStatusDetailRefresh(props.pi, props.ctx, props.deps, props.sessionId);
46886
46912
  this.detail = this.detailRefresh.refresh();
46887
46913
  openStatusDialogs.add(this);
46888
- this.refreshTimer = setInterval(() => {
46914
+ this.refreshTimer = inRootAsyncContext2(() => setInterval(() => {
46889
46915
  if (this.closed)
46890
46916
  return;
46891
46917
  try {
46892
46918
  this.detail = this.detailRefresh.refresh();
46893
46919
  this.props.tui.requestRender();
46894
46920
  } catch {}
46895
- }, REFRESH_INTERVAL_MS);
46921
+ }, REFRESH_INTERVAL_MS));
46896
46922
  }
46897
46923
  handleInput(data) {
46898
46924
  if (this.closed)
@@ -47807,7 +47833,7 @@ No runnable wrapup boundary is available yet; wrapped up 0 messages into 0 compa
47807
47833
  }
47808
47834
  return true;
47809
47835
  };
47810
- const renewal = setInterval(() => {
47836
+ const renewal = inRootAsyncContext2(() => setInterval(() => {
47811
47837
  try {
47812
47838
  renewWrapupMarker({
47813
47839
  lastCompartmentEnd: getLastCompartmentEndMessage(deps.db, sessionId)
@@ -47815,7 +47841,7 @@ No runnable wrapup boundary is available yet; wrapped up 0 messages into 0 compa
47815
47841
  } catch (err) {
47816
47842
  sessionLog2(sessionId, `[pi] /ctx-wrapup marker renewal failed: ${err instanceof Error ? err.message : String(err)}`);
47817
47843
  }
47818
- }, 60000);
47844
+ }, 60000));
47819
47845
  const stopRenewal = () => clearInterval(renewal);
47820
47846
  deps.shutdownSignal?.addEventListener("abort", stopRenewal, { once: true });
47821
47847
  try {
@@ -47890,13 +47916,13 @@ Chunk ${chunkIndex}: wrapping messages ${plan.snapshot.offset}-${plan.snapshot.e
47890
47916
  break;
47891
47917
  }
47892
47918
  const leaseHolder = leaseResult.holderId;
47893
- const leaseRenewal = setInterval(() => {
47919
+ const leaseRenewal = inRootAsyncContext2(() => setInterval(() => {
47894
47920
  try {
47895
47921
  renewCompartmentLease(deps.db, sessionId, leaseHolder);
47896
47922
  } catch (err) {
47897
47923
  sessionLog2(sessionId, `[pi] /ctx-wrapup compartment lease renewal failed: ${err instanceof Error ? err.message : String(err)}`);
47898
47924
  }
47899
- }, COMPARTMENT_LEASE_RENEWAL_MS);
47925
+ }, COMPARTMENT_LEASE_RENEWAL_MS));
47900
47926
  const stopLeaseRenewal = () => clearInterval(leaseRenewal);
47901
47927
  deps.shutdownSignal?.addEventListener("abort", stopLeaseRenewal, {
47902
47928
  once: true
@@ -47930,6 +47956,7 @@ Chunk ${chunkIndex}: wrapping messages ${plan.snapshot.offset}-${plan.snapshot.e
47930
47956
  }).snapshot,
47931
47957
  currentContextLimit: contextLimit,
47932
47958
  historianTimeoutMs: deps.historianTimeoutMs,
47959
+ maxOutputTokens: deps.historianMaxOutputTokens,
47933
47960
  thinkingLevel: deps.historianThinkingLevel,
47934
47961
  memoryEnabled: deps.memoryEnabled,
47935
47962
  autoPromote: deps.autoPromote,
@@ -48283,6 +48310,18 @@ async function bootPiRuntimeWithDeadline(args) {
48283
48310
  return { status: "timed_out", lateAdoption };
48284
48311
  }
48285
48312
 
48313
+ // src/pi-historian-command-options.ts
48314
+ function buildPiHistorianCommandOptions(historian, config) {
48315
+ return {
48316
+ historianModel: historian?.model,
48317
+ historianChunkTokens: historian?.historianChunkTokens ?? deriveHistorianChunkTokens(resolveHistorianContextLimit(historian?.model)),
48318
+ historianFallbacks: historian?.fallbackModels,
48319
+ historianTimeoutMs: historian?.timeoutMs ?? config.historian_timeout_ms,
48320
+ historianMaxOutputTokens: historian?.maxOutputTokens,
48321
+ historianThinkingLevel: historian?.thinkingLevel
48322
+ };
48323
+ }
48324
+
48286
48325
  // src/stale-build-notice.ts
48287
48326
  function bindStaleBuildNotice(ctx, moduleUrl) {
48288
48327
  registerStalePluginBuildHost({
@@ -49412,11 +49451,7 @@ async function startPiMagicContextRuntime(pi, database, dbPath) {
49412
49451
  registerCtxRecompCommand(pi, {
49413
49452
  db,
49414
49453
  runner: recompRunner,
49415
- historianModel: bootProjectDeps.historianConfig?.model,
49416
- historianChunkTokens: deriveHistorianChunkTokens(resolveHistorianContextLimit(bootProjectDeps.historianConfig?.model)),
49417
- historianFallbacks: bootProjectDeps.historianConfig?.fallbackModels,
49418
- historianTimeoutMs: bootProjectDeps.config.historian_timeout_ms,
49419
- historianThinkingLevel: bootProjectDeps.historianConfig?.thinkingLevel,
49454
+ ...buildPiHistorianCommandOptions(bootProjectDeps.historianConfig, bootProjectDeps.config),
49420
49455
  language: bootProjectDeps.config.language,
49421
49456
  memoryEnabled: bootProjectDeps.config.memory.enabled,
49422
49457
  autoPromote: bootProjectDeps.config.memory.auto_promote,
@@ -49428,11 +49463,7 @@ async function startPiMagicContextRuntime(pi, database, dbPath) {
49428
49463
  return {
49429
49464
  db,
49430
49465
  runner: recompRunner,
49431
- historianModel: historian?.model,
49432
- historianChunkTokens: historian?.historianChunkTokens ?? deriveHistorianChunkTokens(resolveHistorianContextLimit(historian?.model)),
49433
- historianFallbacks: historian?.fallbackModels,
49434
- historianTimeoutMs: historian?.timeoutMs ?? current.config.historian_timeout_ms,
49435
- historianThinkingLevel: historian?.thinkingLevel,
49466
+ ...buildPiHistorianCommandOptions(historian, current.config),
49436
49467
  language: current.config.language,
49437
49468
  memoryEnabled: current.config.memory.enabled,
49438
49469
  autoPromote: fresh.memory.auto_promote,
@@ -49445,11 +49476,7 @@ async function startPiMagicContextRuntime(pi, database, dbPath) {
49445
49476
  shutdownSignal: commandLifecycleController.signal,
49446
49477
  db,
49447
49478
  runner: wrapupRunner,
49448
- historianModel: bootProjectDeps.historianConfig?.model,
49449
- historianChunkTokens: deriveHistorianChunkTokens(resolveHistorianContextLimit(bootProjectDeps.historianConfig?.model)),
49450
- historianFallbacks: bootProjectDeps.historianConfig?.fallbackModels,
49451
- historianTimeoutMs: bootProjectDeps.config.historian_timeout_ms,
49452
- historianThinkingLevel: bootProjectDeps.historianConfig?.thinkingLevel,
49479
+ ...buildPiHistorianCommandOptions(bootProjectDeps.historianConfig, bootProjectDeps.config),
49453
49480
  language: bootProjectDeps.config.language,
49454
49481
  memoryEnabled: bootProjectDeps.config.memory.enabled,
49455
49482
  autoPromote: bootProjectDeps.config.memory.auto_promote,
@@ -49464,11 +49491,7 @@ async function startPiMagicContextRuntime(pi, database, dbPath) {
49464
49491
  return {
49465
49492
  db,
49466
49493
  runner: wrapupRunner,
49467
- historianModel: historian?.model,
49468
- historianChunkTokens: historian?.historianChunkTokens ?? deriveHistorianChunkTokens(resolveHistorianContextLimit(historian?.model)),
49469
- historianFallbacks: historian?.fallbackModels,
49470
- historianTimeoutMs: historian?.timeoutMs ?? current.config.historian_timeout_ms,
49471
- historianThinkingLevel: historian?.thinkingLevel,
49494
+ ...buildPiHistorianCommandOptions(historian, current.config),
49472
49495
  language: current.config.language,
49473
49496
  memoryEnabled: current.config.memory.enabled,
49474
49497
  autoPromote: fresh.memory.auto_promote,
@@ -6,7 +6,7 @@ import {
6
6
  getLoggerDiagnostics2,
7
7
  flushLogger2,
8
8
  getLogFilePath2
9
- } from "./index-x3dcnxh0.js";
9
+ } from "./index-gycf3sp7.js";
10
10
  import"./index-0h2mkab2.js";
11
11
  export {
12
12
  flushLogger2 as flushLogger,