@cortexkit/opencode-magic-context 0.49.51 → 0.49.52

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 (73) 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-r77d4fdy.js → context-bkkd7br4.js} +14 -14
  4. package/dist/features/magic-context/storage-meta-persisted.d.ts +1 -1
  5. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  6. package/dist/hooks/magic-context/history-boundary-recovery.d.ts +15 -0
  7. package/dist/hooks/magic-context/history-boundary-recovery.d.ts.map +1 -0
  8. package/dist/hooks/magic-context/inject-compartments.d.ts +11 -0
  9. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  10. package/dist/hooks/magic-context/persist-filtered-noise.d.ts +1 -1
  11. package/dist/hooks/magic-context/persist-filtered-noise.d.ts.map +1 -1
  12. package/dist/hooks/magic-context/rust-mode-transform.d.ts +1 -1
  13. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  14. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +4 -2
  15. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  16. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  17. package/dist/hooks/magic-context/unresolved-history-boundary.d.ts +21 -2
  18. package/dist/hooks/magic-context/unresolved-history-boundary.d.ts.map +1 -1
  19. package/dist/{index-ct3ettqt.js → index-0jc25yjf.js} +3 -3
  20. package/dist/{index-h8g08nxs.js → index-42n4fhxy.js} +92 -57
  21. package/dist/{index-wr2t8zb0.js → index-4xpff2m1.js} +7 -6
  22. package/dist/{index-07rp6xcn.js → index-9gs34125.js} +1 -1
  23. package/dist/{index-z4832qfe.js → index-a4zmmhxs.js} +1 -1
  24. package/dist/{index-5dptmnvd.js → index-fxgaaptn.js} +2 -2
  25. package/dist/{index-s131svmx.js → index-g3j49m95.js} +1 -1
  26. package/dist/{index-v4a1pnny.js → index-k2efzh9r.js} +4 -4
  27. package/dist/{index-gv7dwx5b.js → index-kanfby7e.js} +137 -41
  28. package/dist/{index-mjh63zvw.js → index-q9m97m5g.js} +1 -1
  29. package/dist/{index-30sf7e5k.js → index-qbda6a8k.js} +3 -3
  30. package/dist/{index-97bjd14c.js → index-qtpkkzan.js} +4 -4
  31. package/dist/{index-hkveze74.js → index-x4h461yf.js} +1 -1
  32. package/dist/{index-n0twfvah.js → index-x7jcqpy6.js} +1 -1
  33. package/dist/{index-cwj6qhmf.js → index-xqhejxmd.js} +7 -2
  34. package/dist/index.js +18 -18
  35. package/dist/{message-index-bounded-k0ebpy3y.js → message-index-bounded-71b75npz.js} +2 -2
  36. package/dist/migration-worker.js +1 -1
  37. package/dist/raw-ordinal-warmup-worker.js +3 -3
  38. package/dist/{read-session-chunk-6712p893.js → read-session-chunk-bfv831yx.js} +1 -1
  39. package/dist/{recomp-orchestrator-8ebydg5j.js → recomp-orchestrator-8gj1b7pz.js} +7 -7
  40. package/dist/{render-dtc4qkq4.js → render-b3zcz9x4.js} +5 -5
  41. package/dist/{search-archive-f6hjbnsa.js → search-archive-dp9afcv1.js} +3 -3
  42. package/dist/{search-75bj2430.js → search-y3w590tn.js} +5 -5
  43. package/dist/shared/user-facing-codes.d.ts +7 -2
  44. package/dist/shared/user-facing-codes.d.ts.map +1 -1
  45. package/dist/{transform-postprocess-phase-1bg25094.js → transform-postprocess-phase-8awze16a.js} +8 -8
  46. package/dist/v2/auto-search-worker.js +1 -1
  47. package/dist/v2/chunk-embedding-write-worker.js +1 -1
  48. package/dist/v2/{context-cpbhpxks.js → context-99v7x7fm.js} +135 -38
  49. package/dist/v2/{message-index-bounded-a36rw93p.js → message-index-bounded-2pev910h.js} +2 -2
  50. package/dist/v2/migration-worker.js +1 -1
  51. package/dist/v2/raw-ordinal-warmup-worker.js +3 -3
  52. package/dist/v2/{read-session-chunk-hzhxvhyv.js → read-session-chunk-a454a4d2.js} +1 -1
  53. package/dist/v2/{recomp-orchestrator-yzr49pd0.js → recomp-orchestrator-03fskpsa.js} +6 -6
  54. package/dist/v2/{render-rhaevxv1.js → render-cryx4xsj.js} +5 -5
  55. package/dist/v2/{search-3yrdpr38.js → search-2qj4w7rw.js} +4 -4
  56. package/dist/v2/{search-archive-9924fyk8.js → search-archive-xw2rsq81.js} +3 -3
  57. package/dist/v2/{server-88yvx6r9.js → server-b3h8vqa6.js} +1 -1
  58. package/dist/v2/{server-0k586y7d.js → server-cpstyzvy.js} +3 -3
  59. package/dist/v2/{server-sgn61hht.js → server-dkfs58nq.js} +7 -2
  60. package/dist/v2/{server-16kfxcxj.js → server-kfw4m268.js} +1 -1
  61. package/dist/v2/{server-scp3y4dh.js → server-kreheyw5.js} +1 -1
  62. package/dist/v2/{server-3bfc26r7.js → server-qsvm6w79.js} +1 -1
  63. package/dist/v2/{server-jxrqsn84.js → server-txdsx71h.js} +1 -1
  64. package/dist/v2/{server-016a1whm.js → server-wq9y9a03.js} +92 -57
  65. package/dist/v2/{server-eznem83k.js → server-xjzx27w2.js} +2 -2
  66. package/dist/v2/{server-q93jdtz8.js → server-y5cma2j1.js} +2 -2
  67. package/dist/v2/server.js +2 -2
  68. package/dist/v2/{v2-archive-reader-5ggewg8q.js → v2-archive-reader-3575hw8s.js} +1 -1
  69. package/dist/v2/{wrapup-orchestrator-36c5wyvq.js → wrapup-orchestrator-shzv6t4v.js} +6 -6
  70. package/dist/{v2-archive-reader-gx5ke1d7.js → v2-archive-reader-75fdm0te.js} +1 -1
  71. package/dist/{wrapup-orchestrator-ya31knav.js → wrapup-orchestrator-e0z7nvnx.js} +8 -8
  72. package/package.json +1 -1
  73. package/src/shared/user-facing-codes.ts +8 -2
@@ -194,7 +194,7 @@ import {
194
194
  snapRangeToCompartments,
195
195
  getActiveCompartmentRun,
196
196
  startCompartmentAgent
197
- } from "./index-h8g08nxs.js";
197
+ } from "./index-42n4fhxy.js";
198
198
  import {
199
199
  hasTrustedAbsoluteWall,
200
200
  applyProvenInputFloor,
@@ -426,7 +426,7 @@ import {
426
426
  readRawSessionMessageById2,
427
427
  readSessionChunk2,
428
428
  readRawSessionSeedTail2
429
- } from "./index-07rp6xcn.js";
429
+ } from "./index-9gs34125.js";
430
430
  import {
431
431
  BoundedSessionMap,
432
432
  getMeasuredToolDefinitionTokens
@@ -456,7 +456,7 @@ import {
456
456
  runSqliteOptimize,
457
457
  openDatabase,
458
458
  openCurrentDatabase
459
- } from "./index-z4832qfe.js";
459
+ } from "./index-a4zmmhxs.js";
460
460
  import {
461
461
  unescapeXml,
462
462
  resolveWorkspaceShareCategories,
@@ -565,10 +565,10 @@ import {
565
565
  GLOBAL_USER_PROFILE_PROJECT_PATH,
566
566
  getProjectState,
567
567
  bumpProjectUserProfileVersion
568
- } from "./index-n0twfvah.js";
568
+ } from "./index-x7jcqpy6.js";
569
569
  import {
570
570
  getLastIndexedOrdinal
571
- } from "./index-hkveze74.js";
571
+ } from "./index-x4h461yf.js";
572
572
  import {
573
573
  SESSION_NOTE_CONDITION_ERROR,
574
574
  getNoteByIdInScope,
@@ -681,7 +681,7 @@ import {
681
681
  readGitFileChangeTimesSince,
682
682
  verificationFileExists,
683
683
  normalizeVerificationFiles
684
- } from "./index-cwj6qhmf.js";
684
+ } from "./index-xqhejxmd.js";
685
685
  import {
686
686
  renderSingleStoreMigrationRequiredRefusal,
687
687
  SingleStoreMigrationRequiredError,
@@ -702,13 +702,13 @@ import {
702
702
  resolveMemoriesByIdsForSearch2,
703
703
  unifiedSearch2,
704
704
  formatSearchResults2
705
- } from "./index-30sf7e5k.js";
705
+ } from "./index-qbda6a8k.js";
706
706
  import {
707
707
  scheduleReconciliation,
708
708
  scheduleIncrementalIndex,
709
709
  getMessageIndexQueueHeapStats,
710
710
  clearSessionTracking
711
- } from "./index-s131svmx.js";
711
+ } from "./index-g3j49m95.js";
712
712
  import {
713
713
  flushIgnoredMessages2,
714
714
  clearIgnoredMessages2,
@@ -718,7 +718,7 @@ import {
718
718
  import {
719
719
  setRecompStarting2,
720
720
  setRecompTerminal2
721
- } from "./index-97bjd14c.js";
721
+ } from "./index-qtpkkzan.js";
722
722
  import {
723
723
  makeToolCompositeKey,
724
724
  searchMessageHistoryOffThread,
@@ -796,7 +796,7 @@ import {
796
796
  abortSessionFailClosed2,
797
797
  evaluateEmergencyFailClosed2,
798
798
  runPostTransformPhase2
799
- } from "./index-wr2t8zb0.js";
799
+ } from "./index-4xpff2m1.js";
800
800
  import {
801
801
  ANNOUNCEMENT_VERSION2,
802
802
  ANNOUNCEMENT_FEATURES2,
@@ -811,13 +811,13 @@ import {
811
811
  renderMessageByOrdinal2,
812
812
  renderVerboseRangeForTool2,
813
813
  renderItemByTag2
814
- } from "./index-mjh63zvw.js";
814
+ } from "./index-q9m97m5g.js";
815
815
  import {
816
816
  readV2ArchiveOffThread2
817
- } from "./index-ct3ettqt.js";
817
+ } from "./index-0jc25yjf.js";
818
818
  import {
819
819
  renderSearchArchiveOffThread2
820
- } from "./index-5dptmnvd.js";
820
+ } from "./index-fxgaaptn.js";
821
821
  import {
822
822
  COMPACTION_ENABLED_PATH,
823
823
  isDreamerRunnable,
@@ -16436,7 +16436,7 @@ function registerRpcHandlers(rpcServer, args) {
16436
16436
  const db = readDatabase();
16437
16437
  if (!db)
16438
16438
  return { ok: false, error: "db unavailable" };
16439
- const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-8ebydg5j.js"));
16439
+ const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-8gj1b7pz.js"));
16440
16440
  const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-gamjee2f.js"));
16441
16441
  log2(`[rpc] recomp requested for session ${sessionId}`);
16442
16442
  if (!args.client && !args.hiddenCompletionExecutor) {
@@ -16521,7 +16521,7 @@ function registerRpcHandlers(rpcServer, args) {
16521
16521
  const db = readDatabase();
16522
16522
  if (!db)
16523
16523
  return { ok: false, error: "db unavailable" };
16524
- const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-ya31knav.js"));
16524
+ const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-e0z7nvnx.js"));
16525
16525
  const model = liveSessionState.liveModelBySession.get(sessionId);
16526
16526
  const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
16527
16527
  const ctx = {
@@ -17447,6 +17447,47 @@ function recordCompartmentTriggerError(passOutcome, sessionId, error, log = sess
17447
17447
  log(sessionId, "compartment trigger failed (non-fatal):", error);
17448
17448
  }
17449
17449
 
17450
+ // src/hooks/magic-context/history-boundary-recovery.ts
17451
+ var exhaustedStateBySession = new BoundedSessionMap(512);
17452
+ function inputMessagesKey(messages) {
17453
+ let count = 0;
17454
+ let first = "";
17455
+ let last = "";
17456
+ for (const message of messages) {
17457
+ const id = message.info.id;
17458
+ if (typeof id !== "string" || id.length === 0)
17459
+ continue;
17460
+ if (count === 0)
17461
+ first = id;
17462
+ last = id;
17463
+ count += 1;
17464
+ }
17465
+ return `${count}:${first}:${last}`;
17466
+ }
17467
+ function historyBoundaryRecoveryStateKey(db, sessionId, inputKey) {
17468
+ try {
17469
+ const row = db.prepare(`SELECT
17470
+ (SELECT COUNT(*) FROM compartments WHERE session_id = ?) AS compartments,
17471
+ (SELECT COALESCE(MAX(sequence), -1) FROM compartments WHERE session_id = ?) AS newest,
17472
+ (SELECT COUNT(*) FROM tags WHERE session_id = ? AND status = 'dropped') AS dropped,
17473
+ (SELECT COALESCE(cached_m0_last_baseline_end_message_id, '') FROM session_meta WHERE session_id = ?) AS boundary`).get(sessionId, sessionId, sessionId, sessionId);
17474
+ if (!row)
17475
+ return null;
17476
+ return `${inputKey}|${row.compartments}:${row.newest}|${row.dropped}|${row.boundary ?? ""}`;
17477
+ } catch {
17478
+ return null;
17479
+ }
17480
+ }
17481
+ function markHistoryBoundaryRecoveryExhausted(sessionId, stateKey) {
17482
+ exhaustedStateBySession.set(sessionId, stateKey);
17483
+ }
17484
+ function isHistoryBoundaryRecoveryExhausted(sessionId, stateKey) {
17485
+ return stateKey !== null && exhaustedStateBySession.get(sessionId) === stateKey;
17486
+ }
17487
+ function forgetHistoryBoundaryRecovery(sessionId) {
17488
+ exhaustedStateBySession.delete(sessionId);
17489
+ }
17490
+
17450
17491
  // src/hooks/magic-context/local-wire-reading.ts
17451
17492
  function createLocalWireReadings() {
17452
17493
  const readings = new Map;
@@ -24736,22 +24777,37 @@ function storedHistoryBoundaryPresence(db, sessionId) {
24736
24777
  return;
24737
24778
  }
24738
24779
  }
24780
+ var CAUSE_SENTENCES = {
24781
+ "boundary-not-in-request": "The message the history summary ends on is in the host's store but not in the loaded conversation, so Magic Context could not tell which loaded messages the summary already covers.",
24782
+ "boundary-unordered": "Magic Context could not place the message the history summary ends on in the loaded conversation: either it is not there and the host's store could not order it against the messages that are, or the conversation holds it more than once.",
24783
+ "boundary-missing-from-store": "The message the history summary ends on is no longer in the host's store."
24784
+ };
24785
+ function historyBoundaryRefusalText(cause, remedy) {
24786
+ const failure = renderUserFacingFailure(remedy === "send-again" ? "history_boundary_recovering" : "history_boundary_unresolved", "plain");
24787
+ return cause ? `${CAUSE_SENTENCES[cause]} ${failure}` : failure;
24788
+ }
24739
24789
 
24740
24790
  class UnresolvedHistoryBoundaryError extends Error {
24741
24791
  estimatedTokens;
24742
24792
  contextLimitTokens;
24743
- boundaryPresent;
24793
+ refusalCause;
24794
+ remedy;
24744
24795
  code = "UNRESOLVED_HISTORY_BOUNDARY";
24745
24796
  recoverable = true;
24746
- constructor(estimatedTokens, contextLimitTokens, boundaryPresent) {
24747
- const reason = boundaryPresent === true ? "The boundary row is present in the host store but out of order relative to the loaded history. " : boundaryPresent === false ? "The boundary row is missing from the host store. " : "";
24748
- super(reason + renderUserFacingFailure("history_boundary_unresolved", "plain"));
24797
+ constructor(estimatedTokens, contextLimitTokens, refusalCause, remedy = "flush") {
24798
+ super(historyBoundaryRefusalText(refusalCause, remedy));
24749
24799
  this.estimatedTokens = estimatedTokens;
24750
24800
  this.contextLimitTokens = contextLimitTokens;
24751
- this.boundaryPresent = boundaryPresent;
24801
+ this.refusalCause = refusalCause;
24802
+ this.remedy = remedy;
24752
24803
  this.name = "UnresolvedHistoryBoundaryError";
24753
24804
  }
24754
24805
  }
24806
+ function historyBoundaryRefusalCause(trimRefusal, boundaryInStore) {
24807
+ if (boundaryInStore === false)
24808
+ return "boundary-missing-from-store";
24809
+ return trimRefusal ?? undefined;
24810
+ }
24755
24811
  // src/hooks/magic-context/transform.ts
24756
24812
  var MESSAGE_TOKENS_CACHE_MAX = 100;
24757
24813
  var messageTokensBySession = new BoundedSessionMap(MESSAGE_TOKENS_CACHE_MAX);
@@ -24852,6 +24908,7 @@ function createTransform(deps) {
24852
24908
  const clearSessionLogState = (sessionId) => {
24853
24909
  prefixHoldLogTurnIds.delete(sessionId);
24854
24910
  clearDiagnosticLogState(sessionId);
24911
+ forgetHistoryBoundaryRecovery(sessionId);
24855
24912
  };
24856
24913
  const unmanagedOverWindowSessions = new Set;
24857
24914
  const localWireReadings = createLocalWireReadings();
@@ -25144,6 +25201,7 @@ function createTransform(deps) {
25144
25201
  } else {
25145
25202
  clearDetectedContextLimit(db, sessionId);
25146
25203
  clearEmergencyRecovery(db, sessionId);
25204
+ forgetHistoryBoundaryRecovery(sessionId);
25147
25205
  }
25148
25206
  deps.contextUsageMap.delete(sessionId);
25149
25207
  sessionMeta = {
@@ -25187,6 +25245,8 @@ function createTransform(deps) {
25187
25245
  let recoveryNoEligibleHeadCount = earlyStateSnapshot.protectedTail.recoveryNoEligibleHeadCount;
25188
25246
  let emergencyRecoveryOrigin = null;
25189
25247
  let usagePercentageSynthetic = false;
25248
+ const passInputKey = inputMessagesKey(messages);
25249
+ let recoveryStateKeyAtPassStart = null;
25190
25250
  if (fullFeatureMode && !compactionOff) {
25191
25251
  try {
25192
25252
  const armModel = deps.liveModelBySession?.get(sessionId);
@@ -25204,22 +25264,29 @@ function createTransform(deps) {
25204
25264
  overflowStateMutatedThisPass = true;
25205
25265
  }
25206
25266
  const overflowState = overflowStateMutatedThisPass ? getOverflowState(db, sessionId) : earlyStateSnapshot.overflow;
25207
- emergencyRecoveryArmed = overflowState.needsEmergencyRecovery;
25208
- emergencyRecoveryOrigin = overflowState.emergencyRecoveryOrigin;
25267
+ if (overflowState.needsEmergencyRecovery) {
25268
+ recoveryStateKeyAtPassStart = historyBoundaryRecoveryStateKey(db, sessionId, passInputKey);
25269
+ }
25270
+ const recoveryIdle = overflowState.needsEmergencyRecovery && overflowState.emergencyRecoveryOrigin === "history_boundary_over_window" && isHistoryBoundaryRecoveryExhausted(sessionId, recoveryStateKeyAtPassStart);
25271
+ if (recoveryIdle) {
25272
+ sessionLog2(sessionId, "transform: recovery for an uncut history already ran on this exact state and made no room; idle until the conversation, its summaries or its dropped tool output change");
25273
+ }
25274
+ emergencyRecoveryArmed = overflowState.needsEmergencyRecovery && !recoveryIdle;
25275
+ emergencyRecoveryOrigin = recoveryIdle ? null : overflowState.emergencyRecoveryOrigin;
25209
25276
  if (contextUsageEarly.percentage < 80 && !overflowState.needsEmergencyRecovery) {
25210
25277
  resetProtectedTailNoEligibleHead(db, sessionId);
25211
25278
  recoveryNoEligibleHeadCount = 0;
25212
25279
  }
25213
25280
  const noHeadEscape = overflowState.needsEmergencyRecovery && recoveryNoEligibleHeadCount >= RECOVERY_NO_HEAD_LIMIT;
25214
25281
  recoveryNoHeadEscapeActive = noHeadEscape;
25215
- if (overflowState.needsEmergencyRecovery && contextUsageEarly.percentage < 95 && !noHeadEscape) {
25282
+ if (overflowState.needsEmergencyRecovery && !recoveryIdle && contextUsageEarly.percentage < 95 && !noHeadEscape) {
25216
25283
  sessionLog2(sessionId, `transform: bumping percentage to 95% due to overflow recovery flag (was ${contextUsageEarly.percentage.toFixed(1)}%, detectedLimit=${overflowState.detectedContextLimit || "unknown"})`);
25217
25284
  contextUsageEarly = {
25218
25285
  ...contextUsageEarly,
25219
25286
  percentage: 95
25220
25287
  };
25221
25288
  usagePercentageSynthetic = true;
25222
- } else if (recoveryNoHeadEscapeActive && deps.client) {
25289
+ } else if (recoveryNoHeadEscapeActive && !recoveryIdle && deps.client) {
25223
25290
  withoutSqliteTransformPass2(() => sendStatusNotification2(deps.client, sessionId, "Magic Context can't compact yet — the recent history is a single in-progress block. Continuing; it will compact once the block completes. Run `/ctx-recomp` if this persists.", runNotificationParams(sessionId) ?? {}));
25224
25291
  }
25225
25292
  } catch (error) {
@@ -26303,6 +26370,21 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
26303
26370
  throw contextRefusalError("The request remains over the model window after stripping signed thinking and reclaiming context");
26304
26371
  }
26305
26372
  }
26373
+ const currentModelKeyForRecovery = deps.getModelKey?.(sessionId);
26374
+ const keepRecoveryArmed = () => {
26375
+ if (!emergencyRecoveryArmed || emergencyRecoveryOrigin === null)
26376
+ return;
26377
+ try {
26378
+ if (getOverflowState(db, sessionId).needsEmergencyRecovery)
26379
+ return;
26380
+ recordOverflowDetected(db, sessionId, undefined, currentModelKeyForRecovery, emergencyRecoveryOrigin);
26381
+ } catch (error) {
26382
+ throw new EmergencyFailClosedError("Emergency recovery re-arm failed", {
26383
+ cause: error
26384
+ });
26385
+ }
26386
+ sessionLog2(sessionId, `transform: recovery was cleared during a pass that is not sent; armed again (${emergencyRecoveryOrigin}) for the next turn`);
26387
+ };
26306
26388
  if (postTransformResult.prefixTrimStatus === "refused") {
26307
26389
  const untrimmed = finalWireEstimate ?? estimateFinalWireInputTokens({
26308
26390
  messages,
@@ -26313,8 +26395,35 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
26313
26395
  sessionId
26314
26396
  });
26315
26397
  if (untrimmed.tokens > boundaryContextLimit) {
26316
- sessionLog2(sessionId, `history boundary unresolved: prefix trim refused and the untrimmed request estimate ${untrimmed.tokens} (trusted=${untrimmed.trusted}) exceeds the context limit ${boundaryContextLimit}; not sending it`);
26317
- throw new UnresolvedHistoryBoundaryError(untrimmed.tokens, boundaryContextLimit, storedHistoryBoundaryPresence(db, sessionId));
26398
+ const stateKey = historyBoundaryRecoveryStateKey(db, sessionId, passInputKey);
26399
+ let remedy = "flush";
26400
+ let recovery;
26401
+ if (emergencyRecoveryArmed && emergencyRecoveryOrigin !== null) {
26402
+ const madeRoom = compartmentPhase.published || postTransformResult.droppedCount > 0 || postTransformResult.emergencyReclaimedTokens > 0 || stateKey !== null && recoveryStateKeyAtPassStart !== null && stateKey !== recoveryStateKeyAtPassStart;
26403
+ if (madeRoom) {
26404
+ keepRecoveryArmed();
26405
+ remedy = "send-again";
26406
+ recovery = `${emergencyRecoveryOrigin} recovery made room this pass but not enough; it stays armed for the next turn`;
26407
+ } else {
26408
+ if (stateKey !== null)
26409
+ markHistoryBoundaryRecoveryExhausted(sessionId, stateKey);
26410
+ recovery = `${emergencyRecoveryOrigin} recovery ran this pass and made no room; it stays idle on this state`;
26411
+ }
26412
+ } else if (!untrimmed.trusted) {
26413
+ recovery = "the estimate is not calibrated, so recovery is not armed";
26414
+ } else if (isHistoryBoundaryRecoveryExhausted(sessionId, stateKey)) {
26415
+ recovery = "recovery already ran on this exact state and made no room";
26416
+ } else {
26417
+ try {
26418
+ recordOverflowDetected(db, sessionId, undefined, currentModelKeyForRecovery, "history_boundary_over_window");
26419
+ remedy = "send-again";
26420
+ recovery = "overflow recovery armed (history_boundary_over_window) for the next pass";
26421
+ } catch (error) {
26422
+ recovery = `arming overflow recovery failed: ${getErrorMessage(error)}`;
26423
+ }
26424
+ }
26425
+ sessionLog2(sessionId, `history boundary unresolved: prefix trim refused (${postTransformResult.prefixTrimRefusal ?? "no reason recorded"}) and the untrimmed request estimate ${untrimmed.tokens} (trusted=${untrimmed.trusted}) exceeds the context limit ${boundaryContextLimit}; not sending it; ${recovery}`);
26426
+ throw new UnresolvedHistoryBoundaryError(untrimmed.tokens, boundaryContextLimit, historyBoundaryRefusalCause(postTransformResult.prefixTrimRefusal, storedHistoryBoundaryPresence(db, sessionId)), remedy);
26318
26427
  }
26319
26428
  }
26320
26429
  if (unmanagedOverWindowPass) {
@@ -26334,21 +26443,6 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
26334
26443
  unmanagedOverWindowSessions.delete(sessionId);
26335
26444
  sessionLog2(sessionId, `over-window first pass reduced: the request is about ${servedTokens} tokens (history started at ${unmanagedOverWindowPass.tokens}), under the ${unmanagedOverWindowPass.limit}-token window`);
26336
26445
  }
26337
- const currentModelKeyForRecovery = deps.getModelKey?.(sessionId);
26338
- const keepRecoveryArmed = () => {
26339
- if (!emergencyRecoveryArmed || emergencyRecoveryOrigin === null)
26340
- return;
26341
- try {
26342
- if (getOverflowState(db, sessionId).needsEmergencyRecovery)
26343
- return;
26344
- recordOverflowDetected(db, sessionId, undefined, currentModelKeyForRecovery, emergencyRecoveryOrigin);
26345
- } catch (error) {
26346
- throw new EmergencyFailClosedError("Emergency recovery re-arm failed", {
26347
- cause: error
26348
- });
26349
- }
26350
- sessionLog2(sessionId, `transform: recovery was cleared during a pass that is not sent; armed again (${emergencyRecoveryOrigin}) for the next turn`);
26351
- };
26352
26446
  const timedOutHistorianFailure = compartmentPhase.historianJoinTimedOut ? historianJoinFailClosedMessage({
26353
26447
  timedOut: true,
26354
26448
  budgetMs: compartmentPhase.historianJoinBudgetMs,
@@ -26386,9 +26480,11 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
26386
26480
  });
26387
26481
  if (emergencyFailClosed.disarm) {
26388
26482
  clearEmergencyRecovery(db, sessionId);
26483
+ forgetHistoryBoundaryRecovery(sessionId);
26389
26484
  sessionLog2(sessionId, `emergency disarm: trusted final-wire ${emergencyFailClosed.disarm.finalWireTokens} under limit ${emergencyFailClosed.disarm.provenLimitTokens}`);
26390
26485
  } else if (recoveryAdmissionPass && !emergencyFailClosed.shouldAbort && recoveryServedRequest !== undefined) {
26391
26486
  clearEmergencyRecovery(db, sessionId);
26487
+ forgetHistoryBoundaryRecovery(sessionId);
26392
26488
  sessionLog2(sessionId, `transform: recovery request admitted: about ${recoveryServedRequest.tokens} tokens, within ${recoveryServedRequest.lineTokens} of ${recoveryWindowTokens}; ${emergencyRecoveryOrigin} recovery ends`);
26393
26489
  }
26394
26490
  if (emergencyFailClosed.shouldAbort) {
@@ -5,7 +5,7 @@ import {
5
5
  expandToolPart,
6
6
  visitRawSessionMessages2,
7
7
  readRawSessionMessageById2
8
- } from "./index-07rp6xcn.js";
8
+ } from "./index-9gs34125.js";
9
9
  import {
10
10
  getTagById2
11
11
  } from "./index-bkg4hdyh.js";
@@ -63,18 +63,18 @@ import {
63
63
  sanitizeFtsQuery,
64
64
  searchMemoriesFTS,
65
65
  searchMemoriesFTSUnion
66
- } from "./index-cwj6qhmf.js";
66
+ } from "./index-xqhejxmd.js";
67
67
  import {
68
68
  matchedSearchSnippet,
69
69
  getIndexedMessageCorpusSize
70
- } from "./index-hkveze74.js";
70
+ } from "./index-x4h461yf.js";
71
71
  import {
72
72
  getMessageIndexEpoch,
73
73
  isMessageIndexSearchable,
74
74
  withMemoryHintContent,
75
75
  autoSearchRelevance,
76
76
  recordAutoSearchLane
77
- } from "./index-s131svmx.js";
77
+ } from "./index-g3j49m95.js";
78
78
  import {
79
79
  MESSAGE_FTS_SESSION_FILTER_SQL,
80
80
  withMessageFtsSessionFilter
@@ -3,18 +3,18 @@ import {
3
3
  } from "./index-82dfe8en.js";
4
4
  import {
5
5
  clearEmergencyRecovery
6
- } from "./index-07rp6xcn.js";
6
+ } from "./index-9gs34125.js";
7
7
  import {
8
8
  requestPendingMaterialization,
9
9
  dropSlot
10
- } from "./index-n0twfvah.js";
10
+ } from "./index-x7jcqpy6.js";
11
11
  import {
12
12
  executeContextRecomp
13
- } from "./index-h8g08nxs.js";
13
+ } from "./index-42n4fhxy.js";
14
14
  import {
15
15
  renderUserFacingFailure,
16
16
  userFacingFailureCode
17
- } from "./index-cwj6qhmf.js";
17
+ } from "./index-xqhejxmd.js";
18
18
 
19
19
  // src/hooks/magic-context/recomp-orchestrator.ts
20
20
  function resolveLiveModelKey(liveSessionState, sessionId) {
@@ -9,7 +9,7 @@ import {
9
9
  } from "./index-0tz2fzpq.js";
10
10
  import {
11
11
  cleanUserText2
12
- } from "./index-07rp6xcn.js";
12
+ } from "./index-9gs34125.js";
13
13
  import {
14
14
  recordMessageFtsRowid2,
15
15
  recordIndexedMessageTime2,
@@ -61,7 +61,7 @@ import {
61
61
  serializeProcessedImageMarkers,
62
62
  getPendingPiCompactionMarkerState,
63
63
  logPiCompactionMarkerClear
64
- } from "./index-07rp6xcn.js";
64
+ } from "./index-9gs34125.js";
65
65
  import {
66
66
  stripTagPrefix,
67
67
  isRecord,
@@ -42,8 +42,13 @@ var USER_FACING_FAILURES = {
42
42
  },
43
43
  history_boundary_unresolved: {
44
44
  code: "MC-H04",
45
- sentence: "This request was not sent: Magic Context could not safely place the history summary boundary in the loaded conversation, and the untrimmed request is larger than the model's context window.",
46
- action: "Reopen this session in its current project directory, then run /ctx-recomp to rebuild the history summary. A model with a larger context window can also help."
45
+ sentence: "This request was not sent: it is larger than the model's context window, and Magic Context could not cut the already-summarized history out of it.",
46
+ action: "Run /ctx-flush to compress the history now, then send your message again."
47
+ },
48
+ history_boundary_recovering: {
49
+ code: "MC-H08",
50
+ sentence: "This request was not sent: it is larger than the model's context window, and Magic Context could not cut the already-summarized history out of it.",
51
+ action: "Send your message again: Magic Context will first summarize more of the history and drop old tool output to make it fit."
47
52
  },
48
53
  history_over_window_unmanaged: {
49
54
  code: "MC-H06",
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  detectOverflow,
29
29
  isAnthropicFamilyRoute,
30
30
  readRawSessionMessages2
31
- } from "./index-07rp6xcn.js";
31
+ } from "./index-9gs34125.js";
32
32
  import {
33
33
  setHarness2
34
34
  } from "./index-pavzsdc6.js";
@@ -82,7 +82,7 @@ import {
82
82
  checkCompactionMarkerConsistency,
83
83
  clearInjectionCache,
84
84
  clearNoteNudgeTriggerOnly
85
- } from "./index-h8g08nxs.js";
85
+ } from "./index-42n4fhxy.js";
86
86
  import"./index-sd3egckz.js";
87
87
  import {
88
88
  hasTrustedAbsoluteWall,
@@ -169,7 +169,7 @@ import {
169
169
  parameterDescriptionsFor,
170
170
  MagicContextRpcServer,
171
171
  applyHiddenSubagentTemperature
172
- } from "./index-gv7dwx5b.js";
172
+ } from "./index-kanfby7e.js";
173
173
  import {
174
174
  resolveOpenCodeDbPath,
175
175
  openCodeDbPathExists,
@@ -217,7 +217,7 @@ import {
217
217
  createDbLkgPersistence,
218
218
  registerLkgPersistence,
219
219
  dropSlot
220
- } from "./index-n0twfvah.js";
220
+ } from "./index-x7jcqpy6.js";
221
221
  import {
222
222
  recordSessionProjectIdentity
223
223
  } from "./index-qperbvjn.js";
@@ -232,7 +232,7 @@ import {
232
232
  openDatabaseAsync,
233
233
  isDatabasePersisted,
234
234
  getDatabasePersistenceError
235
- } from "./index-z4832qfe.js";
235
+ } from "./index-a4zmmhxs.js";
236
236
  import {
237
237
  registerExitAbort,
238
238
  unregisterExitAbort
@@ -257,7 +257,7 @@ import"./index-hsyczpn7.js";
257
257
  import {
258
258
  getDefaultSubcConnectionFile,
259
259
  SubcModuleTransport
260
- } from "./index-30sf7e5k.js";
260
+ } from "./index-qbda6a8k.js";
261
261
  import"./index-qt1qqasc.js";
262
262
  import"./index-gz001bx7.js";
263
263
  import {
@@ -295,7 +295,7 @@ import {
295
295
  import"./index-hexdee98.js";
296
296
  import {
297
297
  deleteIndexedMessage
298
- } from "./index-hkveze74.js";
298
+ } from "./index-x4h461yf.js";
299
299
  import"./index-6athgjba.js";
300
300
  import"./index-25tm250q.js";
301
301
  import {
@@ -308,7 +308,7 @@ import {
308
308
  import"./index-4dhv7mqz.js";
309
309
  import"./index-8d7gkgjs.js";
310
310
  import"./index-jjvbk92s.js";
311
- import"./index-cwj6qhmf.js";
311
+ import"./index-xqhejxmd.js";
312
312
  import"./index-90z05d0p.js";
313
313
  import {
314
314
  createTagger,
@@ -317,13 +317,13 @@ import {
317
317
  clearToolPermissionDenied,
318
318
  collectForeignTextParts,
319
319
  resetDegradedCacheCount2
320
- } from "./index-wr2t8zb0.js";
320
+ } from "./index-4xpff2m1.js";
321
321
  import {
322
322
  scheduleClearAndReindex
323
- } from "./index-s131svmx.js";
323
+ } from "./index-g3j49m95.js";
324
324
  import {
325
325
  runManagedRecomp2
326
- } from "./index-97bjd14c.js";
326
+ } from "./index-qtpkkzan.js";
327
327
  import {
328
328
  isValidSemver,
329
329
  compareSemverCore
@@ -331,11 +331,11 @@ import {
331
331
  import"./index-fmsr7v69.js";
332
332
  import {
333
333
  runManagedWrapup2
334
- } from "./index-v4a1pnny.js";
335
- import"./index-mjh63zvw.js";
334
+ } from "./index-k2efzh9r.js";
335
+ import"./index-q9m97m5g.js";
336
336
  import"./index-kaqs6h31.js";
337
- import"./index-ct3ettqt.js";
338
- import"./index-5dptmnvd.js";
337
+ import"./index-0jc25yjf.js";
338
+ import"./index-fxgaaptn.js";
339
339
  import {
340
340
  isDreamerRunnable,
341
341
  isSmartNoteSurfaceAvailable,
@@ -8203,7 +8203,7 @@ var require_src2 = __commonJS(function(exports, module) {
8203
8203
  // package.json
8204
8204
  var package_default = {
8205
8205
  name: "@cortexkit/opencode-magic-context",
8206
- version: "0.49.51",
8206
+ version: "0.49.52",
8207
8207
  type: "module",
8208
8208
  description: "OpenCode plugin for Magic Context — cross-session memory and context management",
8209
8209
  main: "dist/index.js",
@@ -12061,7 +12061,7 @@ async function setup(context) {
12061
12061
  if (claimStorageBackupWarningCheck() && isMagicContextStorageOutsideEngram(storageDir)) {
12062
12062
  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.`);
12063
12063
  }
12064
- const { registerContext } = await import("./context-r77d4fdy.js");
12064
+ const { registerContext } = await import("./context-bkkd7br4.js");
12065
12065
  setHarness2("opencode2");
12066
12066
  bindStaleBuildNotice({}, import.meta.url, "opencode2");
12067
12067
  const duties = await registerContext(context);
@@ -12534,7 +12534,7 @@ var server = async (ctx) => {
12534
12534
  rustReplayParticipant: () => magicContextRuntime.magicContext?.getRustReplayParticipant?.() ?? null,
12535
12535
  onStorageBusyRefusal: async (sessionId, message) => {
12536
12536
  const { sendStatusNotification } = await importPluginModule(() => import("./send-session-notification-gamjee2f.js"));
12537
- const { abortSessionFailClosed } = await importPluginModule(() => import("./transform-postprocess-phase-1bg25094.js"));
12537
+ const { abortSessionFailClosed } = await importPluginModule(() => import("./transform-postprocess-phase-8awze16a.js"));
12538
12538
  await sendStatusNotification(ctx.client, sessionId, message, {
12539
12539
  toastDurationMs: 15000
12540
12540
  });
@@ -17,7 +17,7 @@ import"./index-1d042x6w.js";
17
17
  import"./index-36wseasx.js";
18
18
  import"./index-58e3y90n.js";
19
19
  import"./index-em92bp7f.js";
20
- import"./index-07rp6xcn.js";
20
+ import"./index-9gs34125.js";
21
21
  import"./index-hsv31e69.js";
22
22
  import {
23
23
  MESSAGE_INDEX_MAX_FTS_BYTES,
@@ -26,7 +26,7 @@ import {
26
26
  markMessageIndexDirty,
27
27
  getIndexableContent,
28
28
  indexSingleMessage
29
- } from "./index-hkveze74.js";
29
+ } from "./index-x4h461yf.js";
30
30
  import"./index-2ny9xwdn.js";
31
31
  import"./index-tad3can2.js";
32
32
 
@@ -19,7 +19,7 @@ import"./index-fb3zxn06.js";
19
19
  import {
20
20
  setSqlitePragmaConfig,
21
21
  initializeDatabase
22
- } from "./index-z4832qfe.js";
22
+ } from "./index-a4zmmhxs.js";
23
23
  import"./index-wh9fxds5.js";
24
24
  import"./index-v0p37hm2.js";
25
25
  import"./index-96ztjvkn.js";
@@ -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-gx5ke1d7.js");
22
+ const { serveV2ArchiveReads } = await import("./v2-archive-reader-75fdm0te.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-f6hjbnsa.js");
54
+ const { renderSearchArchive } = await import("./search-archive-dp9afcv1.js");
55
55
  const { readRawSessionMessageIdOrdinalsForRangeFromDb } = await import("./read-session-raw-04ger9zt.js");
56
56
  const archive = input.searchArchive;
57
57
  let raw;
@@ -81,7 +81,7 @@ serveWorkerJobs(async (input, port) => {
81
81
  const { setHarness } = await import("./harness-e4avh192.js");
82
82
  setHarness(input.harness ?? "opencode");
83
83
  const [{ indexMessageInShortChunks }, { configureContextDatabasePragmas }] = await Promise.all([
84
- import("./message-index-bounded-k0ebpy3y.js"),
84
+ import("./message-index-bounded-71b75npz.js"),
85
85
  import("./sqlite-context-pragmas-mv9jqwjh.js")
86
86
  ]);
87
87
  configureContextDatabasePragmas(db);
@@ -38,7 +38,7 @@ import {
38
38
  readSessionChunk2,
39
39
  getRawSessionMessageIdsThrough2,
40
40
  readRawSessionSeedTail2
41
- } from "./index-07rp6xcn.js";
41
+ } from "./index-9gs34125.js";
42
42
  import"./index-bkg4hdyh.js";
43
43
  import"./index-1zx87sdm.js";
44
44
  import"./index-em92bp7f.js";