@cortexkit/opencode-magic-context 0.49.65 → 0.49.67

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 (76) hide show
  1. package/dist/auto-search-worker.js +1 -1
  2. package/dist/chunk-embedding-write-worker.js +1 -1
  3. package/dist/{context-3mfsdp1v.js → context-1acz1d4x.js} +18 -15
  4. package/dist/features/magic-context/compartment-storage.d.ts +7 -0
  5. package/dist/features/magic-context/compartment-storage.d.ts.map +1 -1
  6. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
  7. package/dist/features/magic-context/storage-meta-shared.d.ts +5 -1
  8. package/dist/features/magic-context/storage-meta-shared.d.ts.map +1 -1
  9. package/dist/features/magic-context/types.d.ts +2 -0
  10. package/dist/features/magic-context/types.d.ts.map +1 -1
  11. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  12. package/dist/hooks/magic-context/hook.d.ts +3 -0
  13. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  14. package/dist/hooks/magic-context/inject-compartments.d.ts +24 -1
  15. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  16. package/dist/hooks/magic-context/transform.d.ts +3 -0
  17. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  18. package/dist/hooks/magic-context/unmanaged-over-window.d.ts +4 -0
  19. package/dist/hooks/magic-context/unmanaged-over-window.d.ts.map +1 -1
  20. package/dist/{index-stqmv1mt.js → index-2t9e10mt.js} +72 -21
  21. package/dist/{index-7dj3s7qq.js → index-2x46rnct.js} +1 -1
  22. package/dist/{index-71h616be.js → index-3v5mfapn.js} +1 -1
  23. package/dist/{index-wz0t5e5s.js → index-8a1m48va.js} +3 -3
  24. package/dist/{index-gwb2wpz7.js → index-fybdhbd4.js} +2 -2
  25. package/dist/{index-qn27gh4e.js → index-g53qhdrb.js} +1 -1
  26. package/dist/{index-san8daqa.js → index-gy33sq5h.js} +6 -6
  27. package/dist/{index-x2hwwzk1.js → index-m47yte97.js} +64 -32
  28. package/dist/{index-c0k54yhd.js → index-m6cv2hv3.js} +3 -3
  29. package/dist/{index-g59gpt1j.js → index-nfvyraa3.js} +3 -3
  30. package/dist/{index-ezr8mr1c.js → index-ngrrs3yb.js} +13 -4
  31. package/dist/{index-6kgsfb81.js → index-q73yeb83.js} +1 -1
  32. package/dist/{index-kvfrse61.js → index-t20q6aj6.js} +12 -1
  33. package/dist/{index-0ab398z2.js → index-xmk2a6pq.js} +2 -2
  34. package/dist/{index-8596jbnw.js → index-z10dryn5.js} +5 -5
  35. package/dist/index.js +18 -18
  36. package/dist/{message-index-bounded-zs7ah2te.js → message-index-bounded-f27039js.js} +3 -3
  37. package/dist/migration-worker.js +1 -1
  38. package/dist/plugin/hooks/create-session-hooks.d.ts +6 -0
  39. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  40. package/dist/raw-ordinal-warmup-worker.js +4 -4
  41. package/dist/{read-session-chunk-jf2f8jz8.js → read-session-chunk-4ma2vsva.js} +2 -2
  42. package/dist/{recomp-orchestrator-nyj8ca0y.js → recomp-orchestrator-p9c4jg9m.js} +7 -7
  43. package/dist/{render-n46wpv2n.js → render-h16ea0th.js} +6 -6
  44. package/dist/{search-archive-9k6vsp44.js → search-archive-km2ahm3e.js} +4 -4
  45. package/dist/{search-s386bwwh.js → search-m9rpnh7m.js} +5 -5
  46. package/dist/{storage-tags-2r952wqy.js → storage-tags-ktp70q1e.js} +1 -1
  47. package/dist/{transform-postprocess-phase-8yjcca9t.js → transform-postprocess-phase-120s1ep8.js} +8 -8
  48. package/dist/v2/auto-search-worker.js +1 -1
  49. package/dist/v2/chunk-embedding-write-worker.js +1 -1
  50. package/dist/v2/{context-34sr5ner.js → context-p0z7mrsf.js} +71 -18
  51. package/dist/v2/hooks/context.d.ts.map +1 -1
  52. package/dist/v2/{message-index-bounded-axbs1s97.js → message-index-bounded-td516y9c.js} +3 -3
  53. package/dist/v2/migration-worker.js +1 -1
  54. package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
  55. package/dist/v2/{read-session-chunk-41cm522x.js → read-session-chunk-6dz32wmh.js} +2 -2
  56. package/dist/v2/{recomp-orchestrator-r4gqhhaw.js → recomp-orchestrator-ayy7xzm3.js} +6 -6
  57. package/dist/v2/{render-7v7yx9xb.js → render-gqp4fwqn.js} +6 -6
  58. package/dist/v2/{search-archive-1yc8bh6y.js → search-archive-qn82j8k0.js} +4 -4
  59. package/dist/v2/{search-mabwkzw2.js → search-dhekqtfc.js} +4 -4
  60. package/dist/v2/{server-yxw43z2w.js → server-166m5nrw.js} +13 -4
  61. package/dist/v2/{server-bh9yzxpz.js → server-34vhmd1d.js} +2 -2
  62. package/dist/v2/{server-k97r77x3.js → server-77207nf4.js} +2 -2
  63. package/dist/v2/{server-hcgqsdrh.js → server-jew1m85s.js} +1 -1
  64. package/dist/v2/{server-9rwm2z2h.js → server-n6hdj0fn.js} +64 -32
  65. package/dist/v2/{server-8w9b5exq.js → server-q8ta10e5.js} +1 -1
  66. package/dist/v2/{server-cdddk5d1.js → server-s1a0bwpc.js} +1 -1
  67. package/dist/v2/{server-anh8gf0w.js → server-s66wvkpf.js} +2 -2
  68. package/dist/v2/{server-hb5zm7yh.js → server-verzg5w8.js} +12 -1
  69. package/dist/v2/{server-bnka2vf2.js → server-xwcg55a8.js} +3 -3
  70. package/dist/v2/server.js +2 -2
  71. package/dist/v2/{storage-tags-9zs0gc7w.js → storage-tags-qe8r1n9w.js} +1 -1
  72. package/dist/v2/{v2-archive-reader-pgk140pb.js → v2-archive-reader-tbjwxvc5.js} +1 -1
  73. package/dist/v2/{wrapup-orchestrator-p0ysz3s9.js → wrapup-orchestrator-ksdzyfby.js} +6 -6
  74. package/dist/{v2-archive-reader-cv6veqnz.js → v2-archive-reader-j16k987e.js} +1 -1
  75. package/dist/{wrapup-orchestrator-dxda1svq.js → wrapup-orchestrator-w09bkgmk.js} +8 -8
  76. package/package.json +1 -1
@@ -59,6 +59,7 @@ import {
59
59
  isRecord,
60
60
  escalationBands,
61
61
  sessionDecisionCalibration,
62
+ CACHED_TRIM_PARTIAL_SQL,
62
63
  ensureSessionMetaRow,
63
64
  persistCachedM0,
64
65
  clearCachedM0M1,
@@ -100,7 +101,7 @@ import {
100
101
  foldShrunkPartTags2,
101
102
  getTagNumberByMessageId2,
102
103
  getActiveTagsBySession2
103
- } from "./server-hb5zm7yh.js";
104
+ } from "./server-verzg5w8.js";
104
105
  import {
105
106
  hasMeaningfulUserText2,
106
107
  estimateTokens,
@@ -155,14 +156,14 @@ import {
155
156
  getRawSessionTagKeysThrough2,
156
157
  getLegacyProtectedTailStartOrdinal2,
157
158
  readSessionChunk2
158
- } from "./server-cdddk5d1.js";
159
+ } from "./server-s1a0bwpc.js";
159
160
  import {
160
161
  clearCompressionDepth,
161
162
  clearCompressionDepthRange,
162
163
  toMessageIndexSource,
163
164
  clearIndexedMessagesInTransaction,
164
165
  indexSourcesAfterOrdinal
165
- } from "./server-8w9b5exq.js";
166
+ } from "./server-q8ta10e5.js";
166
167
  import {
167
168
  COMPARTMENT_LEASE_RENEWAL_MS,
168
169
  getCompartmentLeaseBlocker,
@@ -175,6 +176,7 @@ import {
175
176
  queueM0Mutation,
176
177
  getMaxM0MutationId,
177
178
  getCompartments,
179
+ getNewestCompartmentIds,
178
180
  getLastCompartmentEndMessage,
179
181
  getLastCompartmentEndMessageId,
180
182
  getCompartmentsByEndMessageId,
@@ -207,7 +209,7 @@ import {
207
209
  getProjectState,
208
210
  recordSubagentInvocation,
209
211
  getLatestHistorianInvocationId
210
- } from "./server-yxw43z2w.js";
212
+ } from "./server-166m5nrw.js";
211
213
  import {
212
214
  invalidateAutoEmbedSession
213
215
  } from "./server-2amn2s73.js";
@@ -267,7 +269,7 @@ import {
267
269
  LATEST_SUPPORTED_VERSION,
268
270
  getPersistedSchemaVersion,
269
271
  openDatabase
270
- } from "./server-hcgqsdrh.js";
272
+ } from "./server-jew1m85s.js";
271
273
  import {
272
274
  parseCompartmentOutput,
273
275
  resolveWorkspaceShareCategories,
@@ -8215,13 +8217,13 @@ function cutCoveredPrefix(messages, count, coveredInstructions) {
8215
8217
  coveredInstructions.push(message);
8216
8218
  }
8217
8219
  }
8218
- function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, coveredInstructions, projectPath, injectionBudgetTokens, temporalAwareness) {
8220
+ function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, coveredInstructions, projectPath, injectionBudgetTokens, temporalAwareness, frozenBaseline) {
8219
8221
  const cached = injectionCache.get(sessionId);
8220
8222
  if (cached && cached.db !== db) {
8221
8223
  clearInjectionCache(sessionId);
8222
8224
  }
8223
8225
  const usableCached = cached?.db === db ? cached : undefined;
8224
- if (!isCacheBusting && usableCached) {
8226
+ if (!isCacheBusting && usableCached && (!frozenBaseline?.hasCachedM0 || (usableCached.kind === "empty" ? frozenBaseline.boundary === null : usableCached.injection.compartmentEndMessageId === (frozenBaseline.boundary ?? "")))) {
8225
8227
  if (usableCached.kind === "empty") {
8226
8228
  return null;
8227
8229
  }
@@ -8232,7 +8234,7 @@ function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, co
8232
8234
  if (prepared.compartmentEndMessageId.length > 0) {
8233
8235
  const cutoffIndex = findBoundaryIndex(sessionId, messages, prepared.compartmentEndMessageId);
8234
8236
  if (cutoffIndex >= 0) {
8235
- cutCoveredPrefix(messages, cutoffIndex + (isPartialCompartmentEnd(db, sessionId, prepared.compartmentEndMessageId) ? 0 : 1), coveredInstructions);
8237
+ cutCoveredPrefix(messages, cutoffIndex + ((frozenBaseline?.hasCachedM0 ? frozenBaseline.partial : prepared.compartmentEndMessagePartial) ? 0 : 1), coveredInstructions);
8236
8238
  } else {
8237
8239
  sessionLog2(sessionId, `compartment injection: cached boundary ${prepared.compartmentEndMessageId} not in messages (already trimmed), reusing cache`);
8238
8240
  }
@@ -8318,11 +8320,13 @@ function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, co
8318
8320
  const lastEnd = lastCompartment.endMessage;
8319
8321
  const lastEndMessageId = newestCompartmentEndId(compartments) ?? "";
8320
8322
  let trimEndMessageId = lastEndMessageId;
8321
- const baseline = readCachedBaselineState(db, sessionId);
8323
+ const baseline = frozenBaseline ?? readCachedBaselineState(db, sessionId);
8324
+ let trimEndMessagePartial = compartments.some((row) => row.endMessageId === lastEndMessageId && row.endBlockIndex != null);
8322
8325
  if (!isCacheBusting || baseline.hasCachedM0) {
8323
8326
  if (baseline.hasCachedM0) {
8324
8327
  if (baseline.boundary) {
8325
8328
  trimEndMessageId = baseline.boundary;
8329
+ trimEndMessagePartial = baseline.partial;
8326
8330
  } else {
8327
8331
  trimEndMessageId = "";
8328
8332
  }
@@ -8350,12 +8354,14 @@ function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, co
8350
8354
  let needsFreshMaterialization = false;
8351
8355
  let resultEndMessage = lastEnd;
8352
8356
  let resultEndMessageId = null;
8357
+ let resultEndMessagePartial = false;
8353
8358
  const cutoffIndex = findBoundaryIndex(sessionId, messages, trimEndMessageId);
8354
8359
  if (cutoffIndex >= 0) {
8355
8360
  clearDegradedRebuild(sessionId);
8356
- skippedVisibleMessages = cutoffIndex + (isPartialCompartmentEnd(db, sessionId, trimEndMessageId) ? 0 : 1);
8361
+ skippedVisibleMessages = cutoffIndex + (trimEndMessagePartial ? 0 : 1);
8357
8362
  cutCoveredPrefix(messages, skippedVisibleMessages, coveredInstructions);
8358
8363
  resultEndMessageId = trimEndMessageId;
8364
+ resultEndMessagePartial = trimEndMessagePartial;
8359
8365
  } else {
8360
8366
  const degradedCount = noteDegradedRebuild(sessionId);
8361
8367
  if (isCacheBusting) {
@@ -8373,7 +8379,8 @@ function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, co
8373
8379
  const reAnchorCompartment = compartments[reAnchorIndex];
8374
8380
  const reAnchorCutoff = findBoundaryIndex(sessionId, messages, reAnchorCompartment.endMessageId);
8375
8381
  if (reAnchorCutoff >= 0) {
8376
- skippedVisibleMessages = reAnchorCutoff + (isPartialCompartmentEnd(db, sessionId, reAnchorCompartment.endMessageId) ? 0 : 1);
8382
+ resultEndMessagePartial = compartments.some((row) => row.endMessageId === reAnchorCompartment.endMessageId && row.endBlockIndex != null);
8383
+ skippedVisibleMessages = reAnchorCutoff + (resultEndMessagePartial ? 0 : 1);
8377
8384
  cutCoveredPrefix(messages, skippedVisibleMessages, coveredInstructions);
8378
8385
  resultEndMessage = reAnchorCompartment.endMessage;
8379
8386
  resultEndMessageId = reAnchorCompartment.endMessageId;
@@ -8393,6 +8400,7 @@ function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, co
8393
8400
  block,
8394
8401
  compartmentEndMessage: resultEndMessage,
8395
8402
  compartmentEndMessageId: resultEndMessageId,
8403
+ compartmentEndMessagePartial: resultEndMessagePartial,
8396
8404
  compartmentCount: compartments.length,
8397
8405
  skippedVisibleMessages,
8398
8406
  factCount: facts.length,
@@ -8406,11 +8414,13 @@ function prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, co
8406
8414
  return result;
8407
8415
  }
8408
8416
  function readCachedBaselineState(db, sessionId) {
8409
- const row = db.prepare("SELECT cached_m0_bytes AS m0, cached_m0_last_baseline_end_message_id AS boundary FROM session_meta WHERE session_id = ?").get(sessionId);
8417
+ const row = db.prepare(`SELECT cached_m0_bytes AS m0, cached_m0_last_baseline_end_message_id AS boundary,
8418
+ ${CACHED_TRIM_PARTIAL_SQL} AS partial FROM session_meta WHERE session_id = ?`).get(sessionId);
8410
8419
  const boundary = row?.boundary;
8411
8420
  return {
8412
8421
  hasCachedM0: row?.m0 != null,
8413
- boundary: boundary && boundary.length > 0 ? boundary : null
8422
+ boundary: boundary && boundary.length > 0 ? boundary : null,
8423
+ partial: row?.partial === 1
8414
8424
  };
8415
8425
  }
8416
8426
  function renderCompartmentInjection(sessionId, messages, prepared) {
@@ -9393,6 +9403,7 @@ function materializeM0(options) {
9393
9403
  const steps = new WriteTransactionSteps;
9394
9404
  const upgradeIdentity = withCachedM0ToolDefinitionsHash(withCachedM0MemoryIds(encodeCachedM0UpgradeIdentity(snapshotMarkers.upgradeState, snapshotMarkers.compartmentRenderEpoch, snapshotMarkers.muralEnabled, snapshotMarkers.renderBudgetIdentity, snapshotMarkers.memoryRenderEpoch, snapshotMarkers.renderedBudgets ?? null), renderedMemoryIds), snapshotMarkers.toolDefinitionsHash ?? null);
9395
9405
  const baselineEndMessageId = lastCompartmentBoundaryId(compartments);
9406
+ const baselineEndPartial = compartments.some((row) => row.endMessageId === baselineEndMessageId && row.endBlockIndex != null);
9396
9407
  steps.mark("pre_metadata");
9397
9408
  const commitFold = options.onFoldPrepare?.();
9398
9409
  steps.mark("pre_onFoldPrepare");
@@ -9483,6 +9494,8 @@ function materializeM0(options) {
9483
9494
  logSlowWriteTransaction("opencode_materialize_cache", transactionStartedAt, undefined, performance.now(), steps.durations);
9484
9495
  options.state.cachedM0MuralDataUrl = frozenMuralDataUrl;
9485
9496
  options.state.cachedM0MuralHash = frozenMuralHash;
9497
+ options.state.cachedM0TrimBoundaryId = baselineEndMessageId;
9498
+ options.state.cachedM0TrimBoundaryPartial = baselineEndPartial;
9486
9499
  } catch (error) {
9487
9500
  try {
9488
9501
  options.db.exec("ROLLBACK");
@@ -9667,7 +9680,7 @@ function hydrateCachedM0Mural(db, sessionId, state) {
9667
9680
  state.cachedM0MuralHash = row.cached_m0_mural_hash ?? null;
9668
9681
  }
9669
9682
  }
9670
- function readCachedM0M1Row(db, sessionId) {
9683
+ function readCachedM0M1Row(db, sessionId, includePartialBoundary = false) {
9671
9684
  return db.prepare(`SELECT cached_m0_bytes, cached_m0_mural_data_url,
9672
9685
  cached_m0_mural_hash, cached_m1_bytes,
9673
9686
  cached_m0_project_memory_epoch,
@@ -9686,7 +9699,7 @@ function readCachedM0M1Row(db, sessionId) {
9686
9699
  cached_m0_model_key,
9687
9700
  cached_m0_project_identity,
9688
9701
  cached_m0_last_baseline_end_message_id,
9689
- memory_block_ids
9702
+ memory_block_ids${includePartialBoundary ? `, ${CACHED_TRIM_PARTIAL_SQL} AS cached_trim_partial` : ""}
9690
9703
  FROM session_meta
9691
9704
  WHERE session_id = ?`).get(sessionId);
9692
9705
  }
@@ -9745,6 +9758,8 @@ function applyCachedRowToState(state, row) {
9745
9758
  state.cachedM0MuralDataUrl = row.cached_m0_mural_data_url ?? null;
9746
9759
  state.cachedM0MuralHash = row.cached_m0_mural_hash ?? null;
9747
9760
  state.cachedM1Bytes = toBuffer(row.cached_m1_bytes);
9761
+ state.cachedM0TrimBoundaryId = row.cached_m0_last_baseline_end_message_id || null;
9762
+ state.cachedM0TrimBoundaryPartial = row.cached_trim_partial === 1;
9748
9763
  state.cachedM0ProjectMemoryEpoch = markers.projectMemoryEpoch;
9749
9764
  state.cachedM0WorkspaceFingerprint = markers.workspaceFingerprint;
9750
9765
  state.cachedM0ProjectUserProfileVersion = markers.projectUserProfileVersion;
@@ -9778,7 +9793,7 @@ function softRefreshCachedM1(options) {
9778
9793
  const row = readCachedM0M1Row(options.db, options.sessionId);
9779
9794
  if (!row || !cachedRowMatchesState(row, options.state)) {
9780
9795
  options.db.exec("ROLLBACK");
9781
- const sibling = readCachedM0M1Row(options.db, options.sessionId);
9796
+ const sibling = readCachedM0M1Row(options.db, options.sessionId, true);
9782
9797
  if (!sibling)
9783
9798
  throw new RenderM1InvalidMarkersError(options.sessionId);
9784
9799
  applyCachedRowToState(options.state, sibling);
@@ -9798,6 +9813,7 @@ function softRefreshCachedM1(options) {
9798
9813
  const m1Bytes = Buffer2.from(rendered.text, "utf8");
9799
9814
  const visibleIdsJson = JSON.stringify(visibleMemoryIds);
9800
9815
  const baselineEndMessageId = getLastCompartmentEndMessageId(options.db, options.sessionId);
9816
+ const baselineEndPartial = baselineEndMessageId != null && isPartialCompartmentEnd(options.db, options.sessionId, baselineEndMessageId);
9801
9817
  steps.mark("m1Render");
9802
9818
  options.db.prepare(`UPDATE session_meta
9803
9819
  SET cached_m1_bytes = ?,
@@ -9811,6 +9827,8 @@ function softRefreshCachedM1(options) {
9811
9827
  steps.mark("commit");
9812
9828
  logSlowWriteTransaction("opencode_soft_refresh_cache", transactionStartedAt, undefined, performance.now(), steps.durations);
9813
9829
  options.state.cachedM1Bytes = m1Bytes;
9830
+ options.state.cachedM0TrimBoundaryId = baselineEndMessageId;
9831
+ options.state.cachedM0TrimBoundaryPartial = baselineEndPartial;
9814
9832
  options.state.cachedM0UpgradeState = withCachedM0MemoryIds(row.cached_m0_upgrade_state, renderedM0Ids);
9815
9833
  options.state.snapshotMarkers = markers;
9816
9834
  return rendered;
@@ -10120,13 +10138,14 @@ function trimToPreparedPrefix(options, prepared) {
10120
10138
  const boundary = prepared.preparedTrimBoundaryId;
10121
10139
  let outcome = { status: "not-required" };
10122
10140
  if (boundary) {
10141
+ const preserveBoundary = prepared.preparedTrimBoundaryPartial ?? isPartialCompartmentEnd(options.db, options.sessionId, boundary);
10123
10142
  const retireDecisions = (messageIds) => {
10124
10143
  queueAutoSearchHintDecisionRetirement(options.db, options.sessionId, new Set(messageIds));
10125
10144
  };
10126
10145
  const trimAtVisibleBoundary = (reanchor) => {
10127
10146
  const index = findBoundaryIndex(options.sessionId, messages, boundary);
10128
10147
  if (index >= 0) {
10129
- const cut = index + (isPartialCompartmentEnd(options.db, options.sessionId, boundary) ? 0 : 1);
10148
+ const cut = index + (preserveBoundary ? 0 : 1);
10130
10149
  const unplaced = messages.slice(0, cut).filter(isHostRenderedSystemMessage);
10131
10150
  const removed = messages.splice(0, cut, ...unplaced);
10132
10151
  retireDecisions(removed.map((message) => message.info.id).filter((id) => typeof id === "string"));
@@ -10214,7 +10233,7 @@ function trimToPreparedPrefix(options, prepared) {
10214
10233
  }
10215
10234
  lastSourcePosition = position;
10216
10235
  placeUnplaced(position <= boundaryPosition);
10217
- if (position > boundaryPosition || position === boundaryPosition && isPartialCompartmentEnd(options.db, options.sessionId, boundary))
10236
+ if (position > boundaryPosition || position === boundaryPosition && preserveBoundary)
10218
10237
  retained.push(message);
10219
10238
  }
10220
10239
  placeUnplaced(false);
@@ -10225,7 +10244,6 @@ function trimToPreparedPrefix(options, prepared) {
10225
10244
  logBoundaryPrecedesWindow(options, boundary, firstLiveId);
10226
10245
  }
10227
10246
  options.messages.splice(0, options.messages.length, ...retained);
10228
- const preserveBoundary = isPartialCompartmentEnd(options.db, options.sessionId, boundary);
10229
10247
  retireDecisions(sourceOrder.messageIds.slice(0, boundaryPosition + (preserveBoundary ? 0 : 1)));
10230
10248
  outcome = { status: "applied" };
10231
10249
  }
@@ -10240,7 +10258,7 @@ function trimToPreparedPrefix(options, prepared) {
10240
10258
  return outcome;
10241
10259
  }
10242
10260
  function prepareCachedM0M1Replay(db, sessionId) {
10243
- const row = readCachedM0M1Row(db, sessionId);
10261
+ const row = readCachedM0M1Row(db, sessionId, true);
10244
10262
  if (!row?.cached_m0_bytes || !row.cached_m1_bytes)
10245
10263
  return;
10246
10264
  const m0Bytes = toBuffer(row.cached_m0_bytes);
@@ -10258,7 +10276,8 @@ function prepareCachedM0M1Replay(db, sessionId) {
10258
10276
  m0Bytes,
10259
10277
  m1Text,
10260
10278
  preparedMessages,
10261
- preparedTrimBoundaryId: row.cached_m0_last_baseline_end_message_id
10279
+ preparedTrimBoundaryId: row.cached_m0_last_baseline_end_message_id,
10280
+ preparedTrimBoundaryPartial: row.cached_trim_partial === 1
10262
10281
  };
10263
10282
  }
10264
10283
  function headMessagesForSizing(options, folds = false) {
@@ -10321,7 +10340,6 @@ function injectM0M1(options) {
10321
10340
  if (options.state.isSubagent && !options.compactionOff)
10322
10341
  return skipped;
10323
10342
  const completePairAtEntry = options.state.cachedM0Bytes != null && options.state.cachedM1Bytes != null;
10324
- let contentionReplayBoundary = options.contentionFallbackPrefix?.preparedTrimBoundaryId ?? null;
10325
10343
  const decision = mustMaterialize({
10326
10344
  db: options.db,
10327
10345
  sessionId: options.sessionId,
@@ -10359,11 +10377,12 @@ function injectM0M1(options) {
10359
10377
  if (captured?.m0Bytes && captured.m1Text !== null) {
10360
10378
  options.state.cachedM0Bytes = Buffer2.from(captured.m0Bytes);
10361
10379
  options.state.cachedM1Bytes = Buffer2.from(captured.m1Text, "utf8");
10380
+ options.state.cachedM0TrimBoundaryId = captured.preparedTrimBoundaryId ?? null;
10381
+ options.state.cachedM0TrimBoundaryPartial = captured.preparedTrimBoundaryPartial;
10362
10382
  } else {
10363
- const persisted = readCachedM0M1Row(options.db, options.sessionId);
10383
+ const persisted = readCachedM0M1Row(options.db, options.sessionId, true);
10364
10384
  if (persisted?.cached_m0_bytes && persisted.cached_m1_bytes) {
10365
10385
  applyCachedRowToState(options.state, persisted);
10366
- contentionReplayBoundary = persisted.cached_m0_last_baseline_end_message_id;
10367
10386
  }
10368
10387
  }
10369
10388
  }
@@ -10428,11 +10447,19 @@ function injectM0M1(options) {
10428
10447
  const M1_DRIFT_RATIO = 0.15;
10429
10448
  const M1_ABSOLUTE_CAP_RATIO = 0.2;
10430
10449
  const m1AbsoluteBudget = (options.historyBudgetTokens ?? DEFAULT_HISTORY_BUDGET_TOKENS) * M1_ABSOLUTE_CAP_RATIO;
10431
- const m1HasContent = m1Text !== M1_EMPTY_PLACEHOLDER;
10432
- const m1Tokens = m1HasContent ? estimateTokens(m1Text) : 0;
10433
- const m0Tokens = estimateTokens(m0Text);
10434
- const m1OverAbsoluteCap = m1HasContent && m1Tokens > m1AbsoluteBudget;
10435
- if (!rematerialized && !contentionExhausted && m1Recomputed && options.isCacheBustingPass && (memoryUpdateCount > 40 || m1OverAbsoluteCap || m1HasContent && m0Tokens >= M0_DRIFT_RATIO_FLOOR_TOKENS && m1Tokens > m0Tokens * M1_DRIFT_RATIO)) {
10450
+ let driftNeedsRefold = false;
10451
+ if (!rematerialized && !contentionExhausted && m1Recomputed && options.isCacheBustingPass) {
10452
+ driftNeedsRefold = memoryUpdateCount > 40;
10453
+ if (!driftNeedsRefold && m1Text !== M1_EMPTY_PLACEHOLDER) {
10454
+ const m1Tokens = estimateTokens(m1Text);
10455
+ driftNeedsRefold = m1Tokens > m1AbsoluteBudget;
10456
+ if (!driftNeedsRefold) {
10457
+ const m0Tokens = estimateTokens(m0Text);
10458
+ driftNeedsRefold = m0Tokens >= M0_DRIFT_RATIO_FLOOR_TOKENS && m1Tokens > m0Tokens * M1_DRIFT_RATIO;
10459
+ }
10460
+ }
10461
+ }
10462
+ if (driftNeedsRefold) {
10436
10463
  try {
10437
10464
  const refolded = materializeWithRetry(options);
10438
10465
  applyMarkersToState(options.state, refolded.m0Bytes, refolded.snapshotMarkers, refolded.m1Bytes, refolded.renderedMemoryIds);
@@ -10447,7 +10474,10 @@ function injectM0M1(options) {
10447
10474
  if (!options.state.cachedM0MuralDataUrl) {
10448
10475
  m0Text = stripMemoryMuralBlock(m0Text);
10449
10476
  }
10450
- const preparedTrimBoundaryId = options.compactionOff ? null : contentionExhausted && freshFallbackRenderedMemoryIds !== null ? options.db.prepare("SELECT end_message_id FROM compartments WHERE session_id = ? AND sequence <= ? ORDER BY sequence DESC LIMIT 1").get(options.sessionId, options.state.snapshotMarkers.maxCompartmentSeq)?.end_message_id ?? null : contentionExhausted ? contentionReplayBoundary : readCachedBaselineState(options.db, options.sessionId).boundary;
10477
+ const freshContentionFallback = contentionExhausted && freshFallbackRenderedMemoryIds !== null;
10478
+ const persistedBoundary = !options.compactionOff && !freshContentionFallback && !contentionExhausted && options.state.cachedM0TrimBoundaryId === undefined ? readCachedBaselineState(options.db, options.sessionId) : undefined;
10479
+ const preparedTrimBoundaryId = options.compactionOff ? null : freshContentionFallback ? options.db.prepare("SELECT end_message_id FROM compartments WHERE session_id = ? AND sequence <= ? ORDER BY sequence DESC LIMIT 1").get(options.sessionId, options.state.snapshotMarkers.maxCompartmentSeq)?.end_message_id ?? null : options.state.cachedM0TrimBoundaryId !== undefined ? options.state.cachedM0TrimBoundaryId : contentionExhausted ? options.contentionFallbackPrefix?.preparedTrimBoundaryId ?? null : persistedBoundary?.boundary ?? null;
10480
+ const preparedTrimBoundaryPartial = preparedTrimBoundaryId ? freshContentionFallback ? isPartialCompartmentEnd(options.db, options.sessionId, preparedTrimBoundaryId) : options.state.cachedM0TrimBoundaryPartial ?? persistedBoundary?.partial ?? options.contentionFallbackPrefix?.preparedTrimBoundaryPartial ?? true : false;
10451
10481
  const preparedMessages = [];
10452
10482
  const muralForWire = options.state.cachedM0MuralDataUrl ? {
10453
10483
  enabled: true,
@@ -10461,7 +10491,8 @@ function injectM0M1(options) {
10461
10491
  prefixTrim = trimToPreparedPrefix(options, {
10462
10492
  m0RematerializedThisPass: rematerialized,
10463
10493
  materializationContentionRetryExhausted: contentionExhausted,
10464
- preparedTrimBoundaryId
10494
+ preparedTrimBoundaryId,
10495
+ preparedTrimBoundaryPartial
10465
10496
  });
10466
10497
  options.messages.unshift(...structuredClone(preparedMessages));
10467
10498
  } else
@@ -10476,6 +10507,7 @@ function injectM0M1(options) {
10476
10507
  m1Text,
10477
10508
  preparedMessages,
10478
10509
  preparedTrimBoundaryId,
10510
+ preparedTrimBoundaryPartial,
10479
10511
  prefixTrimStatus: prefixTrim.status,
10480
10512
  ...prefixTrim.refusal ? { prefixTrimRefusal: prefixTrim.refusal } : {}
10481
10513
  };
@@ -15304,7 +15336,7 @@ ${chunkText}`,
15304
15336
  return;
15305
15337
  }
15306
15338
  appendCompartments(db, sessionId, persistedCompartments);
15307
- persistedIds = getCompartments(db, sessionId).slice(-persistedCompartments.length).map((c) => c.id);
15339
+ persistedIds = getNewestCompartmentIds(db, sessionId, persistedCompartments.length);
15308
15340
  if (promotionActive && !skipUnanchoredPromotion) {
15309
15341
  try {
15310
15342
  const promotion = promoteSessionFactsDurable(db, sessionId, promotionProjectIdentity, validatedPass.facts ?? []);
@@ -9,7 +9,7 @@ import {
9
9
  } from "./server-pavzsdc6.js";
10
10
  import {
11
11
  cleanUserText2
12
- } from "./server-cdddk5d1.js";
12
+ } from "./server-s1a0bwpc.js";
13
13
  import {
14
14
  recordMessageFtsRowid2,
15
15
  recordIndexedMessageTime2,
@@ -6,7 +6,7 @@ import {
6
6
  estimateMessageTokens,
7
7
  getCandidateToolOwners2,
8
8
  pickNearestPriorOwner2
9
- } from "./server-hb5zm7yh.js";
9
+ } from "./server-verzg5w8.js";
10
10
  import {
11
11
  OMO_INTERNAL_INITIATOR_MARKER,
12
12
  isSystemDirective,
@@ -19,10 +19,10 @@ import {
19
19
  rawMessageWorkerSource2,
20
20
  rawMessageOffThreadRangeReader2,
21
21
  readRawSessionMessageIdOrdinalsForRange2
22
- } from "./server-cdddk5d1.js";
22
+ } from "./server-s1a0bwpc.js";
23
23
  import {
24
24
  readV2ArchiveOffThread2
25
- } from "./server-bnka2vf2.js";
25
+ } from "./server-xwcg55a8.js";
26
26
 
27
27
  // src/tools/ctx-expand/search-archive.ts
28
28
  var archiveReadsOnThisThread = 0;
@@ -2438,6 +2438,12 @@ function getProtectionWindowForSession(db, sessionId, floor) {
2438
2438
 
2439
2439
  // src/features/magic-context/storage-meta-shared.ts
2440
2440
  import { Buffer as Buffer2 } from "node:buffer";
2441
+ var CACHED_TRIM_PARTIAL_SQL = `EXISTS (
2442
+ SELECT 1 FROM compartments
2443
+ WHERE compartments.session_id = session_meta.session_id
2444
+ AND compartments.end_message_id = session_meta.cached_m0_last_baseline_end_message_id
2445
+ AND compartments.end_block_index IS NOT NULL
2446
+ )`;
2441
2447
  var SESSION_META_SELECT_COLUMNS = [
2442
2448
  "session_id",
2443
2449
  "last_response_time",
@@ -2464,6 +2470,7 @@ var SESSION_META_SELECT_COLUMNS = [
2464
2470
  "cached_m0_mural_data_url",
2465
2471
  "cached_m0_mural_hash",
2466
2472
  "cached_m1_bytes",
2473
+ "cached_m0_last_baseline_end_message_id",
2467
2474
  "cached_m0_project_memory_epoch",
2468
2475
  "cached_m0_workspace_fingerprint",
2469
2476
  "cached_m0_project_user_profile_version",
@@ -2623,6 +2630,8 @@ function getDefaultSessionMeta(sessionId) {
2623
2630
  cachedM0MuralDataUrl: null,
2624
2631
  cachedM0MuralHash: null,
2625
2632
  cachedM1Bytes: null,
2633
+ cachedM0TrimBoundaryId: null,
2634
+ cachedM0TrimBoundaryPartial: false,
2626
2635
  cachedM0ProjectMemoryEpoch: null,
2627
2636
  cachedM0WorkspaceFingerprint: null,
2628
2637
  cachedM0ProjectUserProfileVersion: null,
@@ -2700,6 +2709,8 @@ function toSessionMeta(row) {
2700
2709
  cachedM0MuralDataUrl: stringOrNull(row.cached_m0_mural_data_url),
2701
2710
  cachedM0MuralHash: stringOrNull(row.cached_m0_mural_hash),
2702
2711
  cachedM1Bytes: toBufferOrNull(row.cached_m1_bytes),
2712
+ cachedM0TrimBoundaryId: row.cached_m0_last_baseline_end_message_id || null,
2713
+ cachedM0TrimBoundaryPartial: row.cached_trim_partial === 1,
2703
2714
  cachedM0ProjectMemoryEpoch: numOrNull(row.cached_m0_project_memory_epoch),
2704
2715
  cachedM0WorkspaceFingerprint: stringOrNull(row.cached_m0_workspace_fingerprint),
2705
2716
  cachedM0ProjectUserProfileVersion: numOrNull(row.cached_m0_project_user_profile_version),
@@ -8806,4 +8817,4 @@ function deleteToolTagsByOwner(db, sessionId, ownerMsgId) {
8806
8817
  return getDeleteToolTagsByOwnerStatement(db).all(sessionId, ownerMsgId).length;
8807
8818
  }
8808
8819
 
8809
- export { protectedToolTagNumbers, protectedToolTokenCount, stripWellFormedLeadingTagPrefix, stripPersistedAssistantText, byteSize, stripTagPrefix, peelLeadingMcTagNotation, prependTag, isThinkingPart, currentReclaimableToolOutputCount, isRecord, contentTagOwnerMessageId, estimateImageTokensFromDataUrl, estimateToolAttachmentImageTokens, providerVisiblePart, providerVisibleMessage, CLEARED_TODO_STATE_JSON, normalizeTodoStateJson, buildSyntheticTodoPart, computeSyntheticCallId, isSyntheticTodoPart, countRealUserMessages, tailHygieneStructuralSignature, sameTailHygieneStructuralSignature, formatTailHygienePrefixMismatch, refreshTailHygieneBaseline, effectiveTailHygiene, assertTailHygieneContentUnchangedIfEnabled, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, isDroppedToolOutput, toolOutputTokens, decideChannel1, evaluateChannel2, formatChannel1Evaluation, formatChannel2Evaluation, buildChannel2Reminder, buildChannel1Reminder, createFinalWireIncompleteLogger, MERGED_REASONING_PARTS_PREFIX, decodeMergedReasoningParts, readFrozenMergedReasoningParts, MAX_EXECUTE_THRESHOLD, escalationBands, HYGIENE_PROVIDER_UNITS_VERSION, sessionDecisionCalibration, transitionSessionHygieneUnits, readEpochFloorSnapshot, getProtectionWindowForSession, SESSION_META_SELECT_COLUMNS, META_COLUMNS, BOOLEAN_META_KEYS, NULL_BIND_META_KEYS, isSessionMetaRow, getDefaultSessionMeta, ensureSessionMetaRow, toSessionMeta, persistCachedM0, clearCachedM0M1, clearCachedM0, withReplayEnvelopeSnapshot, invalidateReplayEnvelopeSnapshot, isRustMarkerAdmissionFenced, setRustMarkerAdmissionFence, ReplayDocumentError, readReplayEnvelope, readReplayDocument, updateReplayDocument, writeReplayDocument, isEmergencyRecoveryArmed, isProviderOverflowReconfirmed, isProviderOverflowFailClosedProven, getEmergencyRecoveryArmedAt, describeProtectedTailDrainBudgetSkip, loadPersistedUsage, loadProtectedTailMeta, markProtectedTailPolicyV3Seeded, recordProtectedTailPublicationFloor, recordProtectedTailNoEligibleHead, resetProtectedTailNoEligibleHead, getWrapupInProgressState, isWrapupInProgress, acquireWrapupInProgress, updateWrapupInProgress, releaseWrapupInProgress, resolveCompactionModeRecord, getCompactionModeRecord, setCompactionModeRecord, getProtectedTailDrainBudgetSkip, reserveProtectedTailDrainTokens, clearEmergencyDrainLatch, recordHistorianDrainFailure, clearHistorianDrainFailure, rollbackProtectedTailDrainReservation, clearPersistedReasoningWatermark, getEmergencyInputSample, setEmergencyDropSample, clearEmergencyDropSample, getLastNudgeUndropped, setLastNudgeUndropped, getChannel1NudgeState, setChannel1NudgeState, markChannel1PostReduceGracePending, captureChannel1PostReduceGraceBaseline, getChannel2NudgeState, setChannel2NudgeState, casChannel2NudgeState, claimChannel2NudgeState, casChannel2NudgeClaim, getPersistedNoteNudge, setPersistedNoteNudgeTrigger, setPersistedNoteNudgeTriggerMessageId, getNoteNudgeAnchors, getAutoSearchHintDecisions, deliverNoteNudgeAtomic, appendAutoSearchHintDecision, pruneNoteNudgeAnchors, queueAutoSearchHintDecisionRetirement, flushAutoSearchHintDecisionRetirement, getPersistedTodoPermissionDenied, setPersistedTodoPermissionDenied, getPersistedTodoSyntheticAnchor, setPersistedTodoSyntheticAnchor, clearPersistedTodoSyntheticAnchor, getNoteLastReadAt, setNoteLastReadAt, getHistorianFailureState, incrementHistorianFailure, clearHistorianFailureState, getOverflowState, loadTransformPassStateSnapshot, recordOverflowDetected, recordDetectedContextLimit, clearEmergencyRecovery, clearDetectedContextLimit, getPersistedCompactionMarkerState, getCompactionMarkerPublicationState, compareAndSetCompactionMarkerPublicationState, setPersistedCompactionMarkerState, getDeferredClearedCompactionMarkerState, retireDeferredClearedCompactionMarkerState, parseStrippedPlaceholderState, serializeStrippedPlaceholderState, getStrippedPlaceholderIds, applyStrippedPlaceholderDelta, THINKING_BINDING_RECOVERY_FROZEN_PREFIX, THINKING_BINDING_STRIP_ORDER_END_MARKER, thinkingBindingRecoveryFrozenId, COMPACTION_OFF_THINKING_FROZEN_PREFIX, compactionOffThinkingFrozenId, compactionOffFrozenThinkingIds, getThinkingBindingRecoveryTarget, armThinkingBindingRecovery, noteBindingRecoveryAwaitingClear, bindingRecoveryAwaitingClear, retryBindingRecoveryClear, clearThinkingBindingRecoveryIf, getMergedReasoningStrippedIds, addMergedReasoningStrippedIds, getTrailingBlankDecisions, addTrailingBlankDecisions, demoteTrailingBlankKeepDecisions, getStaleReduceStrippedIds, addStaleReduceStrippedIds, getProcessedImageStrippedIds, parseProcessedImageMarkers, serializeProcessedImageMarkers, getProcessedImageMarkers, addProcessedImageStrippedIds, getPendingCompactionMarkerState, getCompactionMarkerHealth, loadPostprocessReplaySnapshot, setPendingCompactionMarkerState, replacePendingCompactionMarkerStateIf, clearPendingCompactionMarkerStateIf, getPendingPiCompactionMarkerState, clearPendingPiCompactionMarkerStateIf, logPiCompactionMarkerClear, getObservedEpochFloor, resolveEpochFloorForPass, getReasoningRemovalState, addRemovedReasoningIds, markDropLeavesReasoning, detectThinkingBindingMismatch, detectLatestTurnThinkingMismatch, isPrefixBoundThinkingModel, detectOverflow, modelAcceptsEmptyContent, isAnthropicFamilyRoute, neutralizeDroppedReasoningPart, restoreNeutralizedReasoningPart, isNeutralizedReasoningPart, variantChangeBustsProviderCache, makeSentinel, makeWholeMessageSentinel, isSentinel, replaySentinelByMessageIds, isInActiveAnthropicTurn, activeAnthropicTurnStart, hasAnthropicReasoning, markServedShapeRepair, prepareServedShapeRepair, stripSystemInjectedMessages, stripDroppedPlaceholderMessages, replayClearedReasoning, replayStrippedInlineThinking, clearOldReasoning, stripClearedReasoning, captureInlineThinkingRepairs, stripInlineThinking, findReasoningBearingAssistantIds, findLatestAssistantReasoningMutationExemptMessage, snapshotTrailingBlankSourceDecisions, findTrailingBlankDecisionCandidates, applyFrozenTrailingBlankDecisions, stripReasoningFromAssistantIds, findMergedReasoningStripDecisions, stripReasoningFromMergedAssistants, getEmptyImageParts, stripProcessedImages, projectOpencodeReasoningBudgetCutoff, DEFAULT_KEEP_REASONING_TOKENS, resolveKeepReasoningTokens, reasoningStepCost, reasoningBudgetCutoff, reasoningTextAndOpaque, opencodeReasoningBudgetCutoff, describeFinalWireTail, estimatePartImageTokens, openCode2ThinkingPayload, estimateMessageTokens, wireContentBytes, createFinalWireUsageTracker, estimateFinalWireInputTokens, estimateAppendedWireTokens, estimateEmergencyDropReclaimTokens, planEmergencyDrop, measureEmergencyTag, snapshotEmergencyServedMass, tagsSinceReading, emergencyServedMassRemovedSince, queuePendingOp, queuePendingDropForUnchangedTag, getPendingOps, hasPendingDropOps, getPendingOpsCount, clearPendingOps, removePendingOp, updateTagByteSize2, getRecentTagOwnerMessageIds2, getActiveTagTokenAggregate2, AGE_RECLAIM_MIN_TOKENS2, getOldestActiveUnprotectedToolTags2, getActiveToolTagsForAgeReclaim2, getTriggerTagTokenUpperBound2, getActiveTagTokenTotalsByMessage2, updateTagTokenCount2, getPersistedToolTagAccounting2, getAllStatusTagTokenTotalsFlat2, getReasoningTokenEstimatesByMessage2, tryGetReasoningTokenEstimatesByMessage2, getMaxTagNumberByOwnerMessage2, TagOwnerSummaryNotReady2, scanTagOwnerSummary2, cachedTagOwnerRatios2, tagOwnerWarmupState2, scanTagOwnerDelta2, installTagOwnerDelta2, installTagOwnerSummary2, isTagOwnerSummaryReady2, tagTokenCountIsNull2, backfillTagTokenCounts2, insertTag2, updateTagStatus2, markTagDropped2, markWhitespaceAssistantTagInert2, getInertWhitespaceAssistantTags2, getInertWhitespaceAssistantTagsByNumbers2, updateTagDropMode2, updateCavemanDepth2, updateTagMessageId2, hasPiFallbackMessageTags2, findAdoptableFallbackTags2, adoptFallbackTagMessageId2, foldShrunkPartTags2, hasPiFallbackToolOwnerTags2, findPiFallbackToolOwnerTags2, adoptPiFallbackToolOwnerTag2, adoptPiFallbackMessageTag2, markTagsCompactedByMessageIds2, deleteTagsByMessageId2, getMaxTagNumberBySession2, getTagNumberByMessageId2, getAssignableTagNumberByMessageId2, getMinMessageTagNumberForRawId2, deriveTagLoadFloor2, TAG_SELECT_COLUMNS2, getTagsBySession2, getActiveTagsBySession2, getTailHygieneTags2, getDroppedTagsBySession2, getTagsForPendingOperations2, getTagsByNumbers2, getNewestToolTagNumbers2, getDroppedTagsByNumbers2, getMaxDroppedTagNumber2, getTagById2, getTopNBySize2, getToolTagNumberByOwner2, getNullOwnerToolTag2, adoptNullOwnerToolTag2, getCandidateToolOwners2, pickNearestPriorOwner2 };
8820
+ export { protectedToolTagNumbers, protectedToolTokenCount, stripWellFormedLeadingTagPrefix, stripPersistedAssistantText, byteSize, stripTagPrefix, peelLeadingMcTagNotation, prependTag, isThinkingPart, currentReclaimableToolOutputCount, isRecord, contentTagOwnerMessageId, estimateImageTokensFromDataUrl, estimateToolAttachmentImageTokens, providerVisiblePart, providerVisibleMessage, CLEARED_TODO_STATE_JSON, normalizeTodoStateJson, buildSyntheticTodoPart, computeSyntheticCallId, isSyntheticTodoPart, countRealUserMessages, tailHygieneStructuralSignature, sameTailHygieneStructuralSignature, formatTailHygienePrefixMismatch, refreshTailHygieneBaseline, effectiveTailHygiene, assertTailHygieneContentUnchangedIfEnabled, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, isDroppedToolOutput, toolOutputTokens, decideChannel1, evaluateChannel2, formatChannel1Evaluation, formatChannel2Evaluation, buildChannel2Reminder, buildChannel1Reminder, createFinalWireIncompleteLogger, MERGED_REASONING_PARTS_PREFIX, decodeMergedReasoningParts, readFrozenMergedReasoningParts, MAX_EXECUTE_THRESHOLD, escalationBands, HYGIENE_PROVIDER_UNITS_VERSION, sessionDecisionCalibration, transitionSessionHygieneUnits, readEpochFloorSnapshot, getProtectionWindowForSession, CACHED_TRIM_PARTIAL_SQL, SESSION_META_SELECT_COLUMNS, META_COLUMNS, BOOLEAN_META_KEYS, NULL_BIND_META_KEYS, isSessionMetaRow, getDefaultSessionMeta, ensureSessionMetaRow, toSessionMeta, persistCachedM0, clearCachedM0M1, clearCachedM0, withReplayEnvelopeSnapshot, invalidateReplayEnvelopeSnapshot, isRustMarkerAdmissionFenced, setRustMarkerAdmissionFence, ReplayDocumentError, readReplayEnvelope, readReplayDocument, updateReplayDocument, writeReplayDocument, isEmergencyRecoveryArmed, isProviderOverflowReconfirmed, isProviderOverflowFailClosedProven, getEmergencyRecoveryArmedAt, describeProtectedTailDrainBudgetSkip, loadPersistedUsage, loadProtectedTailMeta, markProtectedTailPolicyV3Seeded, recordProtectedTailPublicationFloor, recordProtectedTailNoEligibleHead, resetProtectedTailNoEligibleHead, getWrapupInProgressState, isWrapupInProgress, acquireWrapupInProgress, updateWrapupInProgress, releaseWrapupInProgress, resolveCompactionModeRecord, getCompactionModeRecord, setCompactionModeRecord, getProtectedTailDrainBudgetSkip, reserveProtectedTailDrainTokens, clearEmergencyDrainLatch, recordHistorianDrainFailure, clearHistorianDrainFailure, rollbackProtectedTailDrainReservation, clearPersistedReasoningWatermark, getEmergencyInputSample, setEmergencyDropSample, clearEmergencyDropSample, getLastNudgeUndropped, setLastNudgeUndropped, getChannel1NudgeState, setChannel1NudgeState, markChannel1PostReduceGracePending, captureChannel1PostReduceGraceBaseline, getChannel2NudgeState, setChannel2NudgeState, casChannel2NudgeState, claimChannel2NudgeState, casChannel2NudgeClaim, getPersistedNoteNudge, setPersistedNoteNudgeTrigger, setPersistedNoteNudgeTriggerMessageId, getNoteNudgeAnchors, getAutoSearchHintDecisions, deliverNoteNudgeAtomic, appendAutoSearchHintDecision, pruneNoteNudgeAnchors, queueAutoSearchHintDecisionRetirement, flushAutoSearchHintDecisionRetirement, getPersistedTodoPermissionDenied, setPersistedTodoPermissionDenied, getPersistedTodoSyntheticAnchor, setPersistedTodoSyntheticAnchor, clearPersistedTodoSyntheticAnchor, getNoteLastReadAt, setNoteLastReadAt, getHistorianFailureState, incrementHistorianFailure, clearHistorianFailureState, getOverflowState, loadTransformPassStateSnapshot, recordOverflowDetected, recordDetectedContextLimit, clearEmergencyRecovery, clearDetectedContextLimit, getPersistedCompactionMarkerState, getCompactionMarkerPublicationState, compareAndSetCompactionMarkerPublicationState, setPersistedCompactionMarkerState, getDeferredClearedCompactionMarkerState, retireDeferredClearedCompactionMarkerState, parseStrippedPlaceholderState, serializeStrippedPlaceholderState, getStrippedPlaceholderIds, applyStrippedPlaceholderDelta, THINKING_BINDING_RECOVERY_FROZEN_PREFIX, THINKING_BINDING_STRIP_ORDER_END_MARKER, thinkingBindingRecoveryFrozenId, COMPACTION_OFF_THINKING_FROZEN_PREFIX, compactionOffThinkingFrozenId, compactionOffFrozenThinkingIds, getThinkingBindingRecoveryTarget, armThinkingBindingRecovery, noteBindingRecoveryAwaitingClear, bindingRecoveryAwaitingClear, retryBindingRecoveryClear, clearThinkingBindingRecoveryIf, getMergedReasoningStrippedIds, addMergedReasoningStrippedIds, getTrailingBlankDecisions, addTrailingBlankDecisions, demoteTrailingBlankKeepDecisions, getStaleReduceStrippedIds, addStaleReduceStrippedIds, getProcessedImageStrippedIds, parseProcessedImageMarkers, serializeProcessedImageMarkers, getProcessedImageMarkers, addProcessedImageStrippedIds, getPendingCompactionMarkerState, getCompactionMarkerHealth, loadPostprocessReplaySnapshot, setPendingCompactionMarkerState, replacePendingCompactionMarkerStateIf, clearPendingCompactionMarkerStateIf, getPendingPiCompactionMarkerState, clearPendingPiCompactionMarkerStateIf, logPiCompactionMarkerClear, getObservedEpochFloor, resolveEpochFloorForPass, getReasoningRemovalState, addRemovedReasoningIds, markDropLeavesReasoning, detectThinkingBindingMismatch, detectLatestTurnThinkingMismatch, isPrefixBoundThinkingModel, detectOverflow, modelAcceptsEmptyContent, isAnthropicFamilyRoute, neutralizeDroppedReasoningPart, restoreNeutralizedReasoningPart, isNeutralizedReasoningPart, variantChangeBustsProviderCache, makeSentinel, makeWholeMessageSentinel, isSentinel, replaySentinelByMessageIds, isInActiveAnthropicTurn, activeAnthropicTurnStart, hasAnthropicReasoning, markServedShapeRepair, prepareServedShapeRepair, stripSystemInjectedMessages, stripDroppedPlaceholderMessages, replayClearedReasoning, replayStrippedInlineThinking, clearOldReasoning, stripClearedReasoning, captureInlineThinkingRepairs, stripInlineThinking, findReasoningBearingAssistantIds, findLatestAssistantReasoningMutationExemptMessage, snapshotTrailingBlankSourceDecisions, findTrailingBlankDecisionCandidates, applyFrozenTrailingBlankDecisions, stripReasoningFromAssistantIds, findMergedReasoningStripDecisions, stripReasoningFromMergedAssistants, getEmptyImageParts, stripProcessedImages, projectOpencodeReasoningBudgetCutoff, DEFAULT_KEEP_REASONING_TOKENS, resolveKeepReasoningTokens, reasoningStepCost, reasoningBudgetCutoff, reasoningTextAndOpaque, opencodeReasoningBudgetCutoff, describeFinalWireTail, estimatePartImageTokens, openCode2ThinkingPayload, estimateMessageTokens, wireContentBytes, createFinalWireUsageTracker, estimateFinalWireInputTokens, estimateAppendedWireTokens, estimateEmergencyDropReclaimTokens, planEmergencyDrop, measureEmergencyTag, snapshotEmergencyServedMass, tagsSinceReading, emergencyServedMassRemovedSince, queuePendingOp, queuePendingDropForUnchangedTag, getPendingOps, hasPendingDropOps, getPendingOpsCount, clearPendingOps, removePendingOp, updateTagByteSize2, getRecentTagOwnerMessageIds2, getActiveTagTokenAggregate2, AGE_RECLAIM_MIN_TOKENS2, getOldestActiveUnprotectedToolTags2, getActiveToolTagsForAgeReclaim2, getTriggerTagTokenUpperBound2, getActiveTagTokenTotalsByMessage2, updateTagTokenCount2, getPersistedToolTagAccounting2, getAllStatusTagTokenTotalsFlat2, getReasoningTokenEstimatesByMessage2, tryGetReasoningTokenEstimatesByMessage2, getMaxTagNumberByOwnerMessage2, TagOwnerSummaryNotReady2, scanTagOwnerSummary2, cachedTagOwnerRatios2, tagOwnerWarmupState2, scanTagOwnerDelta2, installTagOwnerDelta2, installTagOwnerSummary2, isTagOwnerSummaryReady2, tagTokenCountIsNull2, backfillTagTokenCounts2, insertTag2, updateTagStatus2, markTagDropped2, markWhitespaceAssistantTagInert2, getInertWhitespaceAssistantTags2, getInertWhitespaceAssistantTagsByNumbers2, updateTagDropMode2, updateCavemanDepth2, updateTagMessageId2, hasPiFallbackMessageTags2, findAdoptableFallbackTags2, adoptFallbackTagMessageId2, foldShrunkPartTags2, hasPiFallbackToolOwnerTags2, findPiFallbackToolOwnerTags2, adoptPiFallbackToolOwnerTag2, adoptPiFallbackMessageTag2, markTagsCompactedByMessageIds2, deleteTagsByMessageId2, getMaxTagNumberBySession2, getTagNumberByMessageId2, getAssignableTagNumberByMessageId2, getMinMessageTagNumberForRawId2, deriveTagLoadFloor2, TAG_SELECT_COLUMNS2, getTagsBySession2, getActiveTagsBySession2, getTailHygieneTags2, getDroppedTagsBySession2, getTagsForPendingOperations2, getTagsByNumbers2, getNewestToolTagNumbers2, getDroppedTagsByNumbers2, getMaxDroppedTagNumber2, getTagById2, getTopNBySize2, getToolTagNumberByOwner2, getNullOwnerToolTag2, adoptNullOwnerToolTag2, getCandidateToolOwners2, pickNearestPriorOwner2 };
@@ -139,9 +139,9 @@ async function serveV2ArchiveReads2(port, openConnections) {
139
139
  import("./sqlite-zdgm52sv.js"),
140
140
  import("./store-reader-yaxtdy6f.js"),
141
141
  import("./store-skkhh3rd.js"),
142
- import("./read-session-chunk-41cm522x.js"),
143
- import("./render-7v7yx9xb.js"),
144
- import("./search-archive-1yc8bh6y.js"),
142
+ import("./read-session-chunk-6dz32wmh.js"),
143
+ import("./render-gqp4fwqn.js"),
144
+ import("./search-archive-qn82j8k0.js"),
145
145
  import("./expand-attachments-h33jbgyz.js")
146
146
  ]);
147
147
  const pool = new V2StoreReaderPool;
package/dist/v2/server.js CHANGED
@@ -7875,7 +7875,7 @@ var require_src2 = __commonJS(function(exports, module) {
7875
7875
  // package.json
7876
7876
  var package_default = {
7877
7877
  name: "@cortexkit/opencode-magic-context",
7878
- version: "0.49.65",
7878
+ version: "0.49.67",
7879
7879
  type: "module",
7880
7880
  description: "OpenCode plugin for Magic Context — cross-session memory and context management",
7881
7881
  main: "dist/index.js",
@@ -8196,7 +8196,7 @@ async function setup(context) {
8196
8196
  if (claimStorageBackupWarningCheck() && isMagicContextStorageOutsideEngram(storageDir)) {
8197
8197
  log2(`[magic-context] Magic Context storage is at ${storageDir}, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.`);
8198
8198
  }
8199
- const { registerContext } = await import("./context-34sr5ner.js");
8199
+ const { registerContext } = await import("./context-p0z7mrsf.js");
8200
8200
  setHarness2("opencode2");
8201
8201
  bindStaleBuildNotice({}, import.meta.url, "opencode2");
8202
8202
  const duties = await registerContext(context);
@@ -64,7 +64,7 @@ import {
64
64
  adoptNullOwnerToolTag2,
65
65
  getCandidateToolOwners2,
66
66
  pickNearestPriorOwner2
67
- } from "./server-hb5zm7yh.js";
67
+ } from "./server-verzg5w8.js";
68
68
  import"./server-1zx87sdm.js";
69
69
  import"./server-rz6g5xne.js";
70
70
  import"./server-xepx8t43.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  readV2ArchiveOffThread2,
3
3
  serveV2ArchiveReads2
4
- } from "./server-bnka2vf2.js";
4
+ } from "./server-xwcg55a8.js";
5
5
  import"./server-v0p37hm2.js";
6
6
  import"./server-gzy5w8ya.js";
7
7
  import"./server-1d042x6w.js";
@@ -11,7 +11,7 @@ import {
11
11
  releaseCompartmentLeaseBestEffort,
12
12
  getCompartments,
13
13
  getLastCompartmentEndMessage
14
- } from "./server-yxw43z2w.js";
14
+ } from "./server-166m5nrw.js";
15
15
  import"./server-2amn2s73.js";
16
16
  import"./server-y8xjr8rx.js";
17
17
  import"./server-x6fn9x8q.js";
@@ -24,7 +24,7 @@ import"./server-1d042x6w.js";
24
24
  import"./server-6ash6z8z.js";
25
25
  import"./server-ds8vpfkr.js";
26
26
  import"./server-8pdfmc27.js";
27
- import"./server-8w9b5exq.js";
27
+ import"./server-q8ta10e5.js";
28
28
  import {
29
29
  getWrapupInProgressState,
30
30
  acquireWrapupInProgress,
@@ -32,16 +32,16 @@ import {
32
32
  releaseWrapupInProgress,
33
33
  getHistorianFailureState,
34
34
  clearEmergencyRecovery
35
- } from "./server-hb5zm7yh.js";
35
+ } from "./server-verzg5w8.js";
36
36
  import"./server-xepx8t43.js";
37
- import"./server-hcgqsdrh.js";
37
+ import"./server-jew1m85s.js";
38
38
  import"./server-1zx87sdm.js";
39
39
  import"./server-rz6g5xne.js";
40
40
  import"./server-2ra6pwf3.js";
41
41
  import"./server-3ap5dmhc.js";
42
42
  import {
43
43
  prepareRawSessionOrdinals2
44
- } from "./server-cdddk5d1.js";
44
+ } from "./server-s1a0bwpc.js";
45
45
  import"./server-fr0wbhdn.js";
46
46
  import"./server-jn4pktdk.js";
47
47
  import"./server-afsz3cmx.js";
@@ -63,7 +63,7 @@ import {
63
63
  registerActiveCompartmentRun,
64
64
  setRecompStarting2,
65
65
  setRecompTerminal2
66
- } from "./server-9rwm2z2h.js";
66
+ } from "./server-n6hdj0fn.js";
67
67
  import"./server-qt1qqasc.js";
68
68
  import"./server-z5255w05.js";
69
69
  import"./server-jtq03rkb.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  readV2ArchiveOffThread2,
3
3
  serveV2ArchiveReads2
4
- } from "./index-g59gpt1j.js";
4
+ } from "./index-nfvyraa3.js";
5
5
  import"./index-v0p37hm2.js";
6
6
  import"./index-gzy5w8ya.js";
7
7
  import"./index-1d042x6w.js";
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  runManagedWrapup2
3
- } from "./index-8596jbnw.js";
4
- import"./index-wz0t5e5s.js";
5
- import"./index-x2hwwzk1.js";
3
+ } from "./index-z10dryn5.js";
4
+ import"./index-8a1m48va.js";
5
+ import"./index-m47yte97.js";
6
6
  import"./index-832w615x.js";
7
7
  import"./index-sd3egckz.js";
8
8
  import"./index-n6aye6ny.js";
@@ -10,16 +10,16 @@ import"./index-zxj39ba2.js";
10
10
  import"./index-jjvbk92s.js";
11
11
  import"./index-gq1g9a3a.js";
12
12
  import"./index-4dhv7mqz.js";
13
- import"./index-ezr8mr1c.js";
13
+ import"./index-ngrrs3yb.js";
14
14
  import"./index-tebcx987.js";
15
- import"./index-7dj3s7qq.js";
15
+ import"./index-2x46rnct.js";
16
16
  import"./index-2amn2s73.js";
17
17
  import"./index-6athgjba.js";
18
18
  import"./index-ngwmx6nt.js";
19
19
  import"./index-1sq1krqw.js";
20
20
  import"./index-qt1qqasc.js";
21
- import"./index-6kgsfb81.js";
22
- import"./index-kvfrse61.js";
21
+ import"./index-q73yeb83.js";
22
+ import"./index-t20q6aj6.js";
23
23
  import"./index-1zx87sdm.js";
24
24
  import"./index-x40zr813.js";
25
25
  import"./index-x8a7jmkh.js";
@@ -29,7 +29,7 @@ import"./index-6nqz8hsz.js";
29
29
  import"./index-jg7sbt3v.js";
30
30
  import"./index-snbpdpa3.js";
31
31
  import"./index-pxnzyvjc.js";
32
- import"./index-qn27gh4e.js";
32
+ import"./index-g53qhdrb.js";
33
33
  import"./index-fb3zxn06.js";
34
34
  import"./index-xx05vta0.js";
35
35
  import"./index-fr0wbhdn.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/opencode-magic-context",
3
- "version": "0.49.65",
3
+ "version": "0.49.67",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin for Magic Context — cross-session memory and context management",
6
6
  "main": "dist/index.js",