@cortexkit/pi-magic-context 0.49.74 → 0.49.76

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.
@@ -27,11 +27,11 @@ serveWorkerJobs(async (initial, port) => {
27
27
  { Database, registerSqliteDiagnosticSink },
28
28
  { log }
29
29
  ] = await Promise.all([
30
- import("./embedding-backfill-p0qszhx7.js"),
30
+ import("./embedding-backfill-h1wjzh1n.js"),
31
31
  import("./embedding-cache-7rp4gqzr.js"),
32
32
  import("./storage-memory-0ndn65fm.js"),
33
- import("./project-embedding-registry-2natnvdf.js"),
34
- import("./search-hm8dc1e8.js"),
33
+ import("./project-embedding-registry-zgzq9ehw.js"),
34
+ import("./search-zazd3b88.js"),
35
35
  import("./compartment-chunk-embedding-avkyp2df.js"),
36
36
  import("./embedding-activity-ew6dshfd.js"),
37
37
  import("./harness-9872e0ym.js"),
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ensureMemoryEmbeddings2
3
- } from "./index-w2snpk0j.js";
4
- import"./index-yk0ve8hn.js";
3
+ } from "./index-gczr1m66.js";
4
+ import"./index-0bmsfzqf.js";
5
5
  import"./index-9p40dgkm.js";
6
6
  import"./index-hgd00nas.js";
7
7
  import"./index-yhzhdp3m.js";
@@ -1729,6 +1729,7 @@ function registerProjectEmbedding2(db, projectIdentity, config, features, source
1729
1729
  runtimeFingerprint,
1730
1730
  provider: canReuseProvider ? prior.provider : null,
1731
1731
  generation,
1732
+ searchBackfillAfterId: generationChanged ? undefined : prior.searchBackfillAfterId,
1732
1733
  features: { ...features },
1733
1734
  modelId: providerIdentity === OFF_PROVIDER_IDENTITY ? "off" : providerIdentity,
1734
1735
  chunkModelId: providerIdentity === OFF_PROVIDER_IDENTITY ? "off" : chunkModelId,
@@ -2423,6 +2424,15 @@ function getProjectEmbeddingSnapshot2(projectIdentity) {
2423
2424
  const registration = projectRegistrations.get(projectIdentity);
2424
2425
  return registration ? snapshotFor(registration) : null;
2425
2426
  }
2427
+ function readSearchBackfillCursor2(projectIdentity, generation) {
2428
+ const registration = projectRegistrations.get(projectIdentity);
2429
+ return registration?.generation === generation ? registration.searchBackfillAfterId : undefined;
2430
+ }
2431
+ function writeSearchBackfillCursor2(projectIdentity, generation, expected, afterId) {
2432
+ const registration = projectRegistrations.get(projectIdentity);
2433
+ if (registration?.generation === generation && registration.searchBackfillAfterId === expected)
2434
+ registration.searchBackfillAfterId = afterId;
2435
+ }
2426
2436
  function installProjectEmbeddingSearchBridge2(snapshot, provider) {
2427
2437
  projectRegistrations.set(snapshot.projectIdentity, {
2428
2438
  projectIdentity: snapshot.projectIdentity,
@@ -2430,6 +2440,7 @@ function installProjectEmbeddingSearchBridge2(snapshot, provider) {
2430
2440
  providerIdentity: snapshot.providerIdentity,
2431
2441
  runtimeFingerprint: snapshot.runtimeFingerprint,
2432
2442
  generation: snapshot.generation,
2443
+ searchBackfillAfterId: readSearchBackfillCursor2(snapshot.projectIdentity, snapshot.generation),
2433
2444
  features: { ...snapshot.features },
2434
2445
  modelId: snapshot.modelId,
2435
2446
  chunkModelId: snapshot.chunkModelId,
@@ -3149,4 +3160,4 @@ function _resetProjectEmbeddingRegistryForTests2() {
3149
3160
  setBootQuietPeriodForTests(null);
3150
3161
  }
3151
3162
 
3152
- export { withQueryEmbeddingDeadline, OpenAICompatibleEmbeddingProvider, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitSha, enforceProjectCap, describeShadowBackfillWriteRefusal2, listShadowBackfillStalls2, getShadowBackfillStopReason2, markProjectLoadUntrusted2, contentSha2562, drainProjectEmbeddingIdentityMaintenance2, drainStaleEmbeddingIdentitiesForProject2, registerProjectEmbedding2, registerProjectShadowEmbedding2, getShadowEmbeddingMeasurementCohort2, getPrimaryEmbeddingMeasurementCohort2, embedShadowTextForProject2, enqueueShadowEmbeddingItems2, getShadowBackfillRemaining2, flushShadowEmbeddingBacklog2, registerProjectInObservationMode2, unregisterProjectShadowEmbedding2, unregisterProjectEmbedding2, getProjectEmbeddingSnapshot2, installProjectEmbeddingSearchBridge2, getProjectChunkEmbeddingModelId2, getProjectEmbeddingMaxInputTokens2, embedTextForProject2, embedBatchForProject2, embedItemsForProject2, embedItemsWindowBounded2, embedUnembeddedMemoriesForProject2, drainCommitBacklogForProject2, embedUnembeddedCompartmentChunksForProject2, embedSessionCompartmentChunks2, getEmbeddingCoverageStatus2, getAutoEmbeddingSessionCoverage2, sweepAllRegisteredProjects2, _setTestProviderFactoryForProject2, _resetProjectEmbeddingRegistryForTests2 };
3163
+ export { withQueryEmbeddingDeadline, OpenAICompatibleEmbeddingProvider, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitSha, enforceProjectCap, describeShadowBackfillWriteRefusal2, listShadowBackfillStalls2, getShadowBackfillStopReason2, markProjectLoadUntrusted2, contentSha2562, drainProjectEmbeddingIdentityMaintenance2, drainStaleEmbeddingIdentitiesForProject2, registerProjectEmbedding2, registerProjectShadowEmbedding2, getShadowEmbeddingMeasurementCohort2, getPrimaryEmbeddingMeasurementCohort2, embedShadowTextForProject2, enqueueShadowEmbeddingItems2, getShadowBackfillRemaining2, flushShadowEmbeddingBacklog2, registerProjectInObservationMode2, unregisterProjectShadowEmbedding2, unregisterProjectEmbedding2, getProjectEmbeddingSnapshot2, readSearchBackfillCursor2, writeSearchBackfillCursor2, installProjectEmbeddingSearchBridge2, getProjectChunkEmbeddingModelId2, getProjectEmbeddingMaxInputTokens2, embedTextForProject2, embedBatchForProject2, embedItemsForProject2, embedItemsWindowBounded2, embedUnembeddedMemoriesForProject2, drainCommitBacklogForProject2, embedUnembeddedCompartmentChunksForProject2, embedSessionCompartmentChunks2, getEmbeddingCoverageStatus2, getAutoEmbeddingSessionCoverage2, sweepAllRegisteredProjects2, _setTestProviderFactoryForProject2, _resetProjectEmbeddingRegistryForTests2 };
@@ -140,8 +140,8 @@ async function serveV2ArchiveReads2(port, openConnections) {
140
140
  import("./store-reader-mmfw2h48.js"),
141
141
  import("./store-grcwn6hs.js"),
142
142
  import("./read-session-chunk-ygwyfvtr.js"),
143
- import("./render-cm4572er.js"),
144
- import("./search-archive-8kcsmnzt.js"),
143
+ import("./render-gbeyky54.js"),
144
+ import("./search-archive-33p4gebn.js"),
145
145
  import("./expand-attachments-8sxeyj26.js")
146
146
  ]);
147
147
  const pool = new V2StoreReaderPool;
@@ -7,8 +7,10 @@ import {
7
7
  import {
8
8
  contentSha2562,
9
9
  getProjectEmbeddingSnapshot2,
10
+ readSearchBackfillCursor2,
11
+ writeSearchBackfillCursor2,
10
12
  embedItemsWindowBounded2
11
- } from "./index-yk0ve8hn.js";
13
+ } from "./index-0bmsfzqf.js";
12
14
  import {
13
15
  saveEmbeddingIfHashMatches
14
16
  } from "./index-yhzhdp3m.js";
@@ -23,7 +25,12 @@ async function ensureMemoryEmbeddings2(args) {
23
25
  if (!snapshot?.enabled) {
24
26
  return args.existingEmbeddings;
25
27
  }
26
- const missingMemories = args.memories.filter((memory) => !args.existingEmbeddings.has(memory.id)).sort((a, b) => a.id - b.id).slice(0, SEARCH_BACKFILL_LIMIT);
28
+ const missing = args.memories.filter((memory) => !args.existingEmbeddings.has(memory.id)).sort((a, b) => a.id - b.id);
29
+ const capped = missing.length > SEARCH_BACKFILL_LIMIT;
30
+ const cursor = capped ? readSearchBackfillCursor2(args.projectIdentity, snapshot.generation) : undefined;
31
+ const next = cursor === undefined ? 0 : missing.findIndex((memory) => memory.id > cursor);
32
+ const start = Math.max(0, next);
33
+ const missingMemories = missing.slice(start, start + SEARCH_BACKFILL_LIMIT);
27
34
  if (missingMemories.length === 0) {
28
35
  return args.existingEmbeddings;
29
36
  }
@@ -53,6 +60,10 @@ async function ensureMemoryEmbeddings2(args) {
53
60
  if (!currentSnapshot || currentSnapshot.generation !== result.generation) {
54
61
  return args.existingEmbeddings;
55
62
  }
63
+ if (capped && (cursor !== undefined || result.vectors.size < missingMemories.length)) {
64
+ const nextCursor = start + missingMemories.length < missing.length ? missingMemories.at(-1)?.id : undefined;
65
+ writeSearchBackfillCursor2(args.projectIdentity, snapshot.generation, cursor, nextCursor);
66
+ }
56
67
  for (const [id, embedding] of staged) {
57
68
  args.existingEmbeddings.set(id, embedding);
58
69
  }
@@ -56,7 +56,7 @@ import {
56
56
  getProjectEmbeddingSnapshot2,
57
57
  embedTextForProject2,
58
58
  embedItemsForProject2
59
- } from "./index-yk0ve8hn.js";
59
+ } from "./index-0bmsfzqf.js";
60
60
  import {
61
61
  recordEmbeddingMeasurement
62
62
  } from "./index-hgd00nas.js";
@@ -69,7 +69,7 @@ import {
69
69
  } from "./index-yhzhdp3m.js";
70
70
  import {
71
71
  ensureMemoryEmbeddings2
72
- } from "./index-w2snpk0j.js";
72
+ } from "./index-gczr1m66.js";
73
73
  import {
74
74
  getMemorySelectColumns2,
75
75
  isMemoryRow2,
@@ -70,7 +70,7 @@ import {
70
70
  renderMessageByOrdinal2,
71
71
  renderVerboseRange2,
72
72
  renderItemByTag2
73
- } from "./index-tygcydj7.js";
73
+ } from "./index-xxjx713t.js";
74
74
  import {
75
75
  getLastIndexedOrdinal
76
76
  } from "./index-mm9y1m77.js";
@@ -129,7 +129,7 @@ import {
129
129
  unregisterProjectEmbedding2,
130
130
  getProjectEmbeddingSnapshot2,
131
131
  embedTextForProject2
132
- } from "./index-yk0ve8hn.js";
132
+ } from "./index-0bmsfzqf.js";
133
133
  import {
134
134
  directoryHasGitMetadata,
135
135
  resolveProjectIdentityForSession,
@@ -142,7 +142,7 @@ import {
142
142
  resolveMemoriesByIdsForSearch2,
143
143
  unifiedSearch2,
144
144
  formatSearchResults2
145
- } from "./index-cevw58nn.js";
145
+ } from "./index-px5g7twk.js";
146
146
  import {
147
147
  resolveOpenCodeDbPath,
148
148
  assertOpenCodeStoreGeneration
@@ -1216,6 +1216,12 @@ function getLastCompartmentEndMessageId(db, sessionId) {
1216
1216
  const id = row?.end_message_id;
1217
1217
  return id && id.length > 0 ? id : null;
1218
1218
  }
1219
+ function cachedHistoryCoversLatestCompartment(compartments, m0MaxSequence, historyEndMessageId) {
1220
+ const latest = compartments.at(-1);
1221
+ if (!latest || latest.sequence <= m0MaxSequence)
1222
+ return true;
1223
+ return !!historyEndMessageId && latest.endMessageId === historyEndMessageId && !compartments.some((other) => other !== latest && other.endMessageId === historyEndMessageId);
1224
+ }
1219
1225
  function getCompartmentsByEndMessageId(db, sessionId, endMessageId) {
1220
1226
  const rows = db.prepare("SELECT * FROM compartments WHERE session_id = ? AND end_message_id = ? ORDER BY sequence ASC").all(sessionId, endMessageId).filter(isCompartmentRow);
1221
1227
  return rows.map(toCompartment);
@@ -4725,4 +4731,4 @@ function renderItemByTag2(db, sessionId, number, textIndexDomain = "part", attac
4725
4731
  return selected ? renderPartFull(selected) ?? "" : `Tag ${number}'s original text part is no longer in stored history.`;
4726
4732
  }
4727
4733
 
4728
- export { LkgRecoveryFenceError, clearLkgFenceProcessState, lkgFenceRequiresRebuild, lkgRecoveryFenceUnclean, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, markLkgRecoveryDirty, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, cancelAutoSearchWork, PI_IDENTITY_FOLD_GUARD_LIMIT, readPiIdentityFoldGuards, writePiIdentityFoldGuards, readSessionActivity, observeSessionActivity, backfillSessionActivity, readSessionMeta, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, isNoContentCompartment, HAS_COMPARTMENT_CONTENT_SQL, queueM0Mutation, getMaxM0MutationId, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, getCompartmentsByEndMessageId, appendCompartments, saveRecompStagingPass, getRecompStaging, clearRecompStaging, getRecompPartialRange, setRecompPartialRange, escapeXmlAttr, escapeXmlContent, getUncoveredCompartmentEndThrough, getUncoveredCompartmentEndsThrough, readProjectDocsCanonical, providerResponseFailed, isSuccessfulProviderCompletion, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, hasExplicitRefreshRequest, clearPendingMaterialization, clearReclaimedMaterialization, clearPendingMaterializationOrigin, recordSystemRefreshOwnership, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, acknowledgeSystemPromptDelivery, deferDeliveredSystemRefresh, clearSystemPromptDelivery, saveLkgSlotToDb, loadPersistedLkgSlot, drainStaleLkgSlots, createDbLkgPersistence, replayLkg, beginServedRequest, noteServedPassPermission, noteServedReplay, countServedRefusal, dropServedRecord, commitServedRequest, registerLkgPersistence, LKG_SNAPSHOT_ARRAY, LKG_SNAPSHOT_OBJECT, LKG_SNAPSHOT_KEY, LKG_SNAPSHOT_STRING, LKG_SNAPSHOT_NUMBER, LKG_SNAPSHOT_BOOLEAN, LKG_SNAPSHOT_NULL, LKG_SNAPSHOT_UNDEFINED, contentSnapshotValue, signatureForFields, lkgContentFields, lkgContentDigestFromFields, isLegacyLkgDigest, legacyLkgDigestFromFields, lkgFieldsMatchDigest, exactReusablePrefix, incrementalLkgContentDigests, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, dropSlot, TOOL_SWEEP_SCOPED_MARKER, encodePiContentDecision, decodePiContentDecision, getPiContentDecisions, freezePiContentDecision, withNativeReplayWriteBarrier, getNativeReplayState, saveNativeToolInputs, addNativeReasoningIds, copySessionStateForClone, externalHistorianFailureReason, subprocessExitHistorianFailureReason, countHistorianRuns, getRecentFailedHistorianRunTimes, recordHistorianRun, summarizeImportance, tallyFactsByCategory, queueMemoryMutation, getMemoryMutationsForRender, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationId, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, getSourceContents, recordSubagentInvocation, getLatestHistorianInvocationId, renderMessageByOrdinal2, renderVerboseRange2, renderVerboseRangeForTool2, renderItemByTag2 };
4734
+ export { LkgRecoveryFenceError, clearLkgFenceProcessState, lkgFenceRequiresRebuild, lkgRecoveryFenceUnclean, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, markLkgRecoveryDirty, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, cancelAutoSearchWork, PI_IDENTITY_FOLD_GUARD_LIMIT, readPiIdentityFoldGuards, writePiIdentityFoldGuards, readSessionActivity, observeSessionActivity, backfillSessionActivity, readSessionMeta, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, isNoContentCompartment, HAS_COMPARTMENT_CONTENT_SQL, queueM0Mutation, getMaxM0MutationId, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, cachedHistoryCoversLatestCompartment, getCompartmentsByEndMessageId, appendCompartments, saveRecompStagingPass, getRecompStaging, clearRecompStaging, getRecompPartialRange, setRecompPartialRange, escapeXmlAttr, escapeXmlContent, getUncoveredCompartmentEndThrough, getUncoveredCompartmentEndsThrough, readProjectDocsCanonical, providerResponseFailed, isSuccessfulProviderCompletion, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, hasExplicitRefreshRequest, clearPendingMaterialization, clearReclaimedMaterialization, clearPendingMaterializationOrigin, recordSystemRefreshOwnership, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, acknowledgeSystemPromptDelivery, deferDeliveredSystemRefresh, clearSystemPromptDelivery, saveLkgSlotToDb, loadPersistedLkgSlot, drainStaleLkgSlots, createDbLkgPersistence, replayLkg, beginServedRequest, noteServedPassPermission, noteServedReplay, countServedRefusal, dropServedRecord, commitServedRequest, registerLkgPersistence, LKG_SNAPSHOT_ARRAY, LKG_SNAPSHOT_OBJECT, LKG_SNAPSHOT_KEY, LKG_SNAPSHOT_STRING, LKG_SNAPSHOT_NUMBER, LKG_SNAPSHOT_BOOLEAN, LKG_SNAPSHOT_NULL, LKG_SNAPSHOT_UNDEFINED, contentSnapshotValue, signatureForFields, lkgContentFields, lkgContentDigestFromFields, isLegacyLkgDigest, legacyLkgDigestFromFields, lkgFieldsMatchDigest, exactReusablePrefix, incrementalLkgContentDigests, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, dropSlot, TOOL_SWEEP_SCOPED_MARKER, encodePiContentDecision, decodePiContentDecision, getPiContentDecisions, freezePiContentDecision, withNativeReplayWriteBarrier, getNativeReplayState, saveNativeToolInputs, addNativeReasoningIds, copySessionStateForClone, externalHistorianFailureReason, subprocessExitHistorianFailureReason, countHistorianRuns, getRecentFailedHistorianRunTimes, recordHistorianRun, summarizeImportance, tallyFactsByCategory, queueMemoryMutation, getMemoryMutationsForRender, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationId, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, getSourceContents, recordSubagentInvocation, getLatestHistorianInvocationId, renderMessageByOrdinal2, renderVerboseRange2, renderVerboseRangeForTool2, renderItemByTag2 };
package/dist/index.js CHANGED
@@ -158,7 +158,7 @@ import {
158
158
  registerTodoStateLifecycle,
159
159
  syncCtxMemoryToolEnabled,
160
160
  registerMagicContextTools
161
- } from "./index-6t4m64m1.js";
161
+ } from "./index-vpby27d0.js";
162
162
  import"./index-4knyh1kt.js";
163
163
  import {
164
164
  canonicalModelIdentity,
@@ -500,6 +500,7 @@ import {
500
500
  getCompartments,
501
501
  getLastCompartmentEndMessage,
502
502
  getLastCompartmentEndMessageId,
503
+ cachedHistoryCoversLatestCompartment,
503
504
  getCompartmentsByEndMessageId,
504
505
  appendCompartments,
505
506
  saveRecompStagingPass,
@@ -590,7 +591,7 @@ import {
590
591
  getSourceContents,
591
592
  recordSubagentInvocation,
592
593
  getLatestHistorianInvocationId
593
- } from "./index-tygcydj7.js";
594
+ } from "./index-xxjx713t.js";
594
595
  import {
595
596
  resolveOpenCodeDbPath,
596
597
  assertOpenCodeStoreGeneration,
@@ -788,7 +789,7 @@ import {
788
789
  embedSessionCompartmentChunks2,
789
790
  getEmbeddingCoverageStatus2,
790
791
  getAutoEmbeddingSessionCoverage2
791
- } from "./index-yk0ve8hn.js";
792
+ } from "./index-0bmsfzqf.js";
792
793
  import {
793
794
  USER_FACING_FAILURES,
794
795
  renderUserFacingFailure,
@@ -823,8 +824,8 @@ import {
823
824
  scheduleClearAndReindex,
824
825
  clearSessionTracking,
825
826
  createAutoSearchDiagnostics
826
- } from "./index-cevw58nn.js";
827
- import"./index-w2snpk0j.js";
827
+ } from "./index-px5g7twk.js";
828
+ import"./index-gczr1m66.js";
828
829
  import"./index-3s39a1md.js";
829
830
  import {
830
831
  DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS,
@@ -857,7 +858,7 @@ import {
857
858
  } from "./index-wmkkxwvf.js";
858
859
  import"./index-71rg8j43.js";
859
860
  import"./index-8d2z6503.js";
860
- import"./index-mtpsqxev.js";
861
+ import"./index-0x61mf6t.js";
861
862
  import"./index-cyzsn2hb.js";
862
863
  import {
863
864
  __toESM
@@ -3610,7 +3611,7 @@ function startHostStallProfilerSwitch() {
3610
3611
  // package.json
3611
3612
  var package_default = {
3612
3613
  name: "@cortexkit/pi-magic-context",
3613
- version: "0.49.74",
3614
+ version: "0.49.76",
3614
3615
  type: "module",
3615
3616
  description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
3616
3617
  main: "dist/index.js",
@@ -12818,11 +12819,9 @@ function validateDocsProposal(projectDir, output, budget, expected) {
12818
12819
  while (result.tokens > budget && result.kept.length) {
12819
12820
  const reason = `over budget: ${result.tokens} > ${budget}`;
12820
12821
  const latestGrowth = [...result.kept].reverse().find((item) => item.grew);
12821
- if (latestGrowth)
12822
- overBudget.set(latestGrowth.index, reason);
12823
- else
12824
- for (const item of result.kept)
12825
- overBudget.set(item.index, reason);
12822
+ if (!latestGrowth)
12823
+ break;
12824
+ overBudget.set(latestGrowth.index, reason);
12826
12825
  result = applyChanges(items, originals, overBudget);
12827
12826
  }
12828
12827
  const diffs = FILES.filter((file) => originals[file] !== result.docs[file]).map((file) => diff(file, originals[file], result.docs[file])).join("");
@@ -36311,14 +36310,16 @@ function softRefreshCachedM1Pi(args) {
36311
36310
  throw new PiMaterializeContentionError(`missing sibling cached m[0]/m[1] for ${args.state.sessionId}`);
36312
36311
  }
36313
36312
  const siblingCompartments = getRenderableCompartmentsPi(args.db, args.state);
36313
+ const replayed = applyCachedPiRow({
36314
+ row: sibling,
36315
+ state: args.state,
36316
+ compartmentsForNormalization: siblingCompartments
36317
+ });
36314
36318
  return {
36315
- ...applyCachedPiRow({
36316
- row: sibling,
36317
- state: args.state,
36318
- compartmentsForNormalization: siblingCompartments
36319
- }),
36319
+ ...replayed,
36320
36320
  memoryUpdateCount: 0,
36321
- recomputed: false
36321
+ recomputed: false,
36322
+ wrapupPublicationUnconfirmed: args.state.skipPressureRefold === true && !cachedHistoryCoversLatestCompartment(siblingCompartments, replayed.markers.maxCompartmentSeq, replayed.markers.lastBaselineEndMessageId)
36322
36323
  };
36323
36324
  }
36324
36325
  steps.mark("staleCheck");
@@ -36481,6 +36482,7 @@ function injectM0M1Pi(state, db, piMessages, entryIds, recomputeM1ThisPass = fal
36481
36482
  let contentionExhausted = false;
36482
36483
  let memoryUpdateCount = 0;
36483
36484
  let m1Recomputed = false;
36485
+ let wrapupPublicationUnconfirmed;
36484
36486
  let freshFallbackRenderedMemoryIds = null;
36485
36487
  if (decision.value) {
36486
36488
  try {
@@ -36559,6 +36561,7 @@ function injectM0M1Pi(state, db, piMessages, entryIds, recomputeM1ThisPass = fal
36559
36561
  markers = refreshed.markers;
36560
36562
  memoryUpdateCount = refreshed.memoryUpdateCount;
36561
36563
  m1Recomputed = refreshed.recomputed;
36564
+ wrapupPublicationUnconfirmed = refreshed.wrapupPublicationUnconfirmed;
36562
36565
  } catch (error) {
36563
36566
  if (!state.allowFreshContentionFallback)
36564
36567
  throw error;
@@ -36641,6 +36644,7 @@ function injectM0M1Pi(state, db, piMessages, entryIds, recomputeM1ThisPass = fal
36641
36644
  m0Bytes: m0.length,
36642
36645
  m1Bytes: m1.length,
36643
36646
  contentionExhausted,
36647
+ wrapupPublicationUnconfirmed,
36644
36648
  renderedBoundary,
36645
36649
  m1RenderedCoverage,
36646
36650
  syntheticLeadingCount: insertionIndex + 2
@@ -43885,8 +43889,8 @@ function piImageWirePlaceholder(args) {
43885
43889
  return args.role === "toolResult" ? PI_NON_VISION_TOOL_IMAGE_PLACEHOLDER : PI_NON_VISION_USER_IMAGE_PLACEHOLDER;
43886
43890
  return;
43887
43891
  }
43888
- function piToolImageWireTokens(args) {
43889
- const placeholder = piImageWirePlaceholder({ ...args, role: "toolResult" });
43892
+ function piImageWireTokens(args) {
43893
+ const placeholder = piImageWirePlaceholder(args);
43890
43894
  return placeholder === undefined ? PI_IMAGE_TOKENS : estimateTokens(placeholder);
43891
43895
  }
43892
43896
  function piMessagesWithWireImages(messages, args) {
@@ -47764,8 +47768,8 @@ function createPiTranscript(source, sessionId, entryIds, options = {}) {
47764
47768
  toolRemovals.set(working, removals);
47765
47769
  if (options.authorizeToolRemoval)
47766
47770
  toolRemovalAuthorization.set(working, options.authorizeToolRemoval);
47767
- if (options.toolImageTokens)
47768
- toolImageTokenCost.set(working, options.toolImageTokens);
47771
+ if (options.imageTokens)
47772
+ imageTokenCost.set(working, options.imageTokens);
47769
47773
  const emptyRemovedMessages = new Set;
47770
47774
  const toolInputChanges = new Map;
47771
47775
  const transcriptMessages = buildTranscriptView(working, sessionId, (messageIndex, toolCallId) => {
@@ -48028,7 +48032,7 @@ function createPiUserArrayPart(working, messageIndex, partIndex, markDirty) {
48028
48032
  ignored: msg.ignored || part?.ignored,
48029
48033
  imageTokens() {
48030
48034
  const current = working[messageIndex].content;
48031
- return Array.isArray(current) && current[partIndex]?.type === "image" ? PI_IMAGE_TOKENS : 0;
48035
+ return Array.isArray(current) && current[partIndex]?.type === "image" ? imageTokenCost.get(working)?.(messageIndex, partIndex) ?? PI_IMAGE_TOKENS : 0;
48032
48036
  },
48033
48037
  id: undefined,
48034
48038
  getText() {
@@ -48239,8 +48243,7 @@ function createPiToolResultPart(working, messageIndex, partIndex, markDirty) {
48239
48243
  imageTokens() {
48240
48244
  if (working[messageIndex].content[partIndex]?.type !== "image")
48241
48245
  return 0;
48242
- const cost = toolImageTokenCost.get(working);
48243
- return cost ? cost(messageIndex, partIndex) : PI_IMAGE_TOKENS;
48246
+ return imageTokenCost.get(working)?.(messageIndex, partIndex) ?? PI_IMAGE_TOKENS;
48244
48247
  },
48245
48248
  remove() {
48246
48249
  return markToolRemoval(working, messageIndex, partIndex);
@@ -48339,7 +48342,7 @@ function extractStableId(msg, index, entryIds) {
48339
48342
  }
48340
48343
  var toolRemovals = new WeakMap;
48341
48344
  var toolRemovalAuthorization = new WeakMap;
48342
- var toolImageTokenCost = new WeakMap;
48345
+ var imageTokenCost = new WeakMap;
48343
48346
  function markToolRemoval(working, messageIndex, partIndex) {
48344
48347
  const removals = toolRemovals.get(working);
48345
48348
  if (!removals)
@@ -52918,9 +52921,10 @@ async function runPipeline(args) {
52918
52921
  saved: nativeRemovalInputs,
52919
52922
  canApply: isCacheBustingPass
52920
52923
  }),
52921
- toolImageTokens: (messageIndex, partIndex) => {
52924
+ imageTokens: (messageIndex, partIndex) => {
52922
52925
  const message = args.messages[messageIndex];
52923
- return piToolImageWireTokens({
52926
+ return piImageWireTokens({
52927
+ role: message?.role,
52924
52928
  block: Array.isArray(message?.content) ? message.content[partIndex] : undefined,
52925
52929
  stripped: imageStrippedMessage(message, messageIndex),
52926
52930
  modelAcceptsImages: args.modelAcceptsImages !== false
@@ -53899,7 +53903,7 @@ async function runPipeline(args) {
53899
53903
  }
53900
53904
  }
53901
53905
  if (!heldHeadReleasedForSystemChange) {
53902
- if (wrapupPending && isCacheBustingPass && !protectedSignedPrefix && wireInjectionResult.injected && !wireInjectionResult.contentionExhausted) {
53906
+ if (wrapupPending && isCacheBustingPass && !protectedSignedPrefix && wireInjectionResult.injected && !wireInjectionResult.contentionExhausted && !wireInjectionResult.wrapupPublicationUnconfirmed) {
53903
53907
  clearPendingMaterializationOrigin(pendingMaterializationSessions, args.sessionId, "user_wrapup");
53904
53908
  historyWasConsumedThisPass = true;
53905
53909
  }
@@ -18,6 +18,8 @@ import {
18
18
  unregisterProjectShadowEmbedding2,
19
19
  unregisterProjectEmbedding2,
20
20
  getProjectEmbeddingSnapshot2,
21
+ readSearchBackfillCursor2,
22
+ writeSearchBackfillCursor2,
21
23
  installProjectEmbeddingSearchBridge2,
22
24
  getProjectChunkEmbeddingModelId2,
23
25
  getProjectEmbeddingMaxInputTokens2,
@@ -34,7 +36,7 @@ import {
34
36
  sweepAllRegisteredProjects2,
35
37
  _setTestProviderFactoryForProject2,
36
38
  _resetProjectEmbeddingRegistryForTests2
37
- } from "./index-yk0ve8hn.js";
39
+ } from "./index-0bmsfzqf.js";
38
40
  import"./index-9p40dgkm.js";
39
41
  import"./index-hgd00nas.js";
40
42
  import"./index-yhzhdp3m.js";
@@ -85,10 +87,12 @@ export {
85
87
  installProjectEmbeddingSearchBridge2 as installProjectEmbeddingSearchBridge,
86
88
  listShadowBackfillStalls2 as listShadowBackfillStalls,
87
89
  markProjectLoadUntrusted2 as markProjectLoadUntrusted,
90
+ readSearchBackfillCursor2 as readSearchBackfillCursor,
88
91
  registerProjectEmbedding2 as registerProjectEmbedding,
89
92
  registerProjectInObservationMode2 as registerProjectInObservationMode,
90
93
  registerProjectShadowEmbedding2 as registerProjectShadowEmbedding,
91
94
  sweepAllRegisteredProjects2 as sweepAllRegisteredProjects,
92
95
  unregisterProjectEmbedding2 as unregisterProjectEmbedding,
93
- unregisterProjectShadowEmbedding2 as unregisterProjectShadowEmbedding
96
+ unregisterProjectShadowEmbedding2 as unregisterProjectShadowEmbedding,
97
+ writeSearchBackfillCursor2 as writeSearchBackfillCursor
94
98
  };
@@ -19,7 +19,7 @@ serveWorkerJobs(async (input, port) => {
19
19
  await main();
20
20
  async function main() {
21
21
  if (input.v2ArchiveReader) {
22
- const { serveV2ArchiveReads } = await import("./v2-archive-reader-ycw2nxf1.js");
22
+ const { serveV2ArchiveReads } = await import("./v2-archive-reader-5cydt27v.js");
23
23
  await serveV2ArchiveReads(port, openConnections);
24
24
  return;
25
25
  }
@@ -51,7 +51,7 @@ serveWorkerJobs(async (input, port) => {
51
51
  await runMessageFtsRowidMapBackfill(db);
52
52
  reply = { kind: "fts-rowid-backfill" };
53
53
  } else if (input.searchArchive) {
54
- const { renderSearchArchive } = await import("./search-archive-8kcsmnzt.js");
54
+ const { renderSearchArchive } = await import("./search-archive-33p4gebn.js");
55
55
  const { readRawSessionMessageIdOrdinalsForRangeFromDb } = await import("./read-session-raw-0tytrjye.js");
56
56
  const archive = input.searchArchive;
57
57
  let raw;
@@ -3,7 +3,7 @@ import {
3
3
  renderVerboseRange2,
4
4
  renderVerboseRangeForTool2,
5
5
  renderItemByTag2
6
- } from "./index-tygcydj7.js";
6
+ } from "./index-xxjx713t.js";
7
7
  import"./index-k7a8x7ba.js";
8
8
  import"./index-mm9y1m77.js";
9
9
  import"./index-hgd00nas.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  renderSearchArchive2
3
3
  } from "./index-cyzsn2hb.js";
4
- import"./index-mtpsqxev.js";
4
+ import"./index-0x61mf6t.js";
5
5
  import"./index-8d2z6503.js";
6
6
  import"./index-apff8dej.js";
7
7
  import"./index-6gwasf0v.js";
@@ -5,13 +5,13 @@ import {
5
5
  resolveMemoriesByIdsForSearch2,
6
6
  unifiedSearch2,
7
7
  formatSearchResults2
8
- } from "./index-cevw58nn.js";
8
+ } from "./index-px5g7twk.js";
9
9
  import"./index-k7a8x7ba.js";
10
10
  import"./index-mm9y1m77.js";
11
11
  import"./index-8d2z6503.js";
12
- import"./index-w2snpk0j.js";
12
+ import"./index-gczr1m66.js";
13
13
  import"./index-29nw7n1r.js";
14
- import"./index-yk0ve8hn.js";
14
+ import"./index-0bmsfzqf.js";
15
15
  import"./index-9p40dgkm.js";
16
16
  import"./index-hgd00nas.js";
17
17
  import"./index-yhzhdp3m.js";
@@ -34,27 +34,27 @@ import {
34
34
  resolvePiHarnessKind,
35
35
  reportSubagentStartupError,
36
36
  registerMagicContextTools
37
- } from "./index-6t4m64m1.js";
37
+ } from "./index-vpby27d0.js";
38
38
  import"./index-vcegxfwg.js";
39
39
  import"./index-5rcjs14a.js";
40
40
  import"./index-cxczethe.js";
41
41
  import"./index-txcs0vnj.js";
42
- import"./index-yk0ve8hn.js";
42
+ import"./index-0bmsfzqf.js";
43
43
  import"./index-hgd00nas.js";
44
44
  import"./index-9p40dgkm.js";
45
45
  import"./index-79xfn84y.js";
46
46
  import"./index-yhzhdp3m.js";
47
- import"./index-cevw58nn.js";
48
- import"./index-tygcydj7.js";
47
+ import"./index-px5g7twk.js";
48
+ import"./index-xxjx713t.js";
49
49
  import"./index-mm9y1m77.js";
50
50
  import"./index-6gwasf0v.js";
51
51
  import"./index-6x556c2q.js";
52
52
  import"./index-nvh6d3bz.js";
53
53
  import"./index-k7a8x7ba.js";
54
54
  import"./index-8d2z6503.js";
55
- import"./index-mtpsqxev.js";
55
+ import"./index-0x61mf6t.js";
56
56
  import"./index-cyzsn2hb.js";
57
- import"./index-w2snpk0j.js";
57
+ import"./index-gczr1m66.js";
58
58
  import"./index-29nw7n1r.js";
59
59
  import"./index-3s39a1md.js";
60
60
  import"./index-1ts77n1b.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  readV2ArchiveOffThread2,
3
3
  serveV2ArchiveReads2
4
- } from "./index-mtpsqxev.js";
4
+ } from "./index-0x61mf6t.js";
5
5
  import"./index-8sqebjzk.js";
6
6
  import"./index-2qtx0q6h.js";
7
7
  import"./index-x2n261wp.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/pi-magic-context",
3
- "version": "0.49.74",
3
+ "version": "0.49.76",
4
4
  "type": "module",
5
5
  "description": "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
6
6
  "main": "dist/index.js",