@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.
- package/dist/auto-search-worker.js +1 -1
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/{context-r77d4fdy.js → context-bkkd7br4.js} +14 -14
- package/dist/features/magic-context/storage-meta-persisted.d.ts +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/hooks/magic-context/history-boundary-recovery.d.ts +15 -0
- package/dist/hooks/magic-context/history-boundary-recovery.d.ts.map +1 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts +11 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/persist-filtered-noise.d.ts +1 -1
- package/dist/hooks/magic-context/persist-filtered-noise.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +4 -2
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/unresolved-history-boundary.d.ts +21 -2
- package/dist/hooks/magic-context/unresolved-history-boundary.d.ts.map +1 -1
- package/dist/{index-ct3ettqt.js → index-0jc25yjf.js} +3 -3
- package/dist/{index-h8g08nxs.js → index-42n4fhxy.js} +92 -57
- package/dist/{index-wr2t8zb0.js → index-4xpff2m1.js} +7 -6
- package/dist/{index-07rp6xcn.js → index-9gs34125.js} +1 -1
- package/dist/{index-z4832qfe.js → index-a4zmmhxs.js} +1 -1
- package/dist/{index-5dptmnvd.js → index-fxgaaptn.js} +2 -2
- package/dist/{index-s131svmx.js → index-g3j49m95.js} +1 -1
- package/dist/{index-v4a1pnny.js → index-k2efzh9r.js} +4 -4
- package/dist/{index-gv7dwx5b.js → index-kanfby7e.js} +137 -41
- package/dist/{index-mjh63zvw.js → index-q9m97m5g.js} +1 -1
- package/dist/{index-30sf7e5k.js → index-qbda6a8k.js} +3 -3
- package/dist/{index-97bjd14c.js → index-qtpkkzan.js} +4 -4
- package/dist/{index-hkveze74.js → index-x4h461yf.js} +1 -1
- package/dist/{index-n0twfvah.js → index-x7jcqpy6.js} +1 -1
- package/dist/{index-cwj6qhmf.js → index-xqhejxmd.js} +7 -2
- package/dist/index.js +18 -18
- package/dist/{message-index-bounded-k0ebpy3y.js → message-index-bounded-71b75npz.js} +2 -2
- package/dist/migration-worker.js +1 -1
- package/dist/raw-ordinal-warmup-worker.js +3 -3
- package/dist/{read-session-chunk-6712p893.js → read-session-chunk-bfv831yx.js} +1 -1
- package/dist/{recomp-orchestrator-8ebydg5j.js → recomp-orchestrator-8gj1b7pz.js} +7 -7
- package/dist/{render-dtc4qkq4.js → render-b3zcz9x4.js} +5 -5
- package/dist/{search-archive-f6hjbnsa.js → search-archive-dp9afcv1.js} +3 -3
- package/dist/{search-75bj2430.js → search-y3w590tn.js} +5 -5
- package/dist/shared/user-facing-codes.d.ts +7 -2
- package/dist/shared/user-facing-codes.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-1bg25094.js → transform-postprocess-phase-8awze16a.js} +8 -8
- package/dist/v2/auto-search-worker.js +1 -1
- package/dist/v2/chunk-embedding-write-worker.js +1 -1
- package/dist/v2/{context-cpbhpxks.js → context-99v7x7fm.js} +135 -38
- package/dist/v2/{message-index-bounded-a36rw93p.js → message-index-bounded-2pev910h.js} +2 -2
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/raw-ordinal-warmup-worker.js +3 -3
- package/dist/v2/{read-session-chunk-hzhxvhyv.js → read-session-chunk-a454a4d2.js} +1 -1
- package/dist/v2/{recomp-orchestrator-yzr49pd0.js → recomp-orchestrator-03fskpsa.js} +6 -6
- package/dist/v2/{render-rhaevxv1.js → render-cryx4xsj.js} +5 -5
- package/dist/v2/{search-3yrdpr38.js → search-2qj4w7rw.js} +4 -4
- package/dist/v2/{search-archive-9924fyk8.js → search-archive-xw2rsq81.js} +3 -3
- package/dist/v2/{server-88yvx6r9.js → server-b3h8vqa6.js} +1 -1
- package/dist/v2/{server-0k586y7d.js → server-cpstyzvy.js} +3 -3
- package/dist/v2/{server-sgn61hht.js → server-dkfs58nq.js} +7 -2
- package/dist/v2/{server-16kfxcxj.js → server-kfw4m268.js} +1 -1
- package/dist/v2/{server-scp3y4dh.js → server-kreheyw5.js} +1 -1
- package/dist/v2/{server-3bfc26r7.js → server-qsvm6w79.js} +1 -1
- package/dist/v2/{server-jxrqsn84.js → server-txdsx71h.js} +1 -1
- package/dist/v2/{server-016a1whm.js → server-wq9y9a03.js} +92 -57
- package/dist/v2/{server-eznem83k.js → server-xjzx27w2.js} +2 -2
- package/dist/v2/{server-q93jdtz8.js → server-y5cma2j1.js} +2 -2
- package/dist/v2/server.js +2 -2
- package/dist/v2/{v2-archive-reader-5ggewg8q.js → v2-archive-reader-3575hw8s.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-36c5wyvq.js → wrapup-orchestrator-shzv6t4v.js} +6 -6
- package/dist/{v2-archive-reader-gx5ke1d7.js → v2-archive-reader-75fdm0te.js} +1 -1
- package/dist/{wrapup-orchestrator-ya31knav.js → wrapup-orchestrator-e0z7nvnx.js} +8 -8
- package/package.json +1 -1
- 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-
|
|
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-
|
|
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-
|
|
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-
|
|
568
|
+
} from "./index-x7jcqpy6.js";
|
|
569
569
|
import {
|
|
570
570
|
getLastIndexedOrdinal
|
|
571
|
-
} from "./index-
|
|
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-
|
|
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-
|
|
705
|
+
} from "./index-qbda6a8k.js";
|
|
706
706
|
import {
|
|
707
707
|
scheduleReconciliation,
|
|
708
708
|
scheduleIncrementalIndex,
|
|
709
709
|
getMessageIndexQueueHeapStats,
|
|
710
710
|
clearSessionTracking
|
|
711
|
-
} from "./index-
|
|
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-
|
|
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-
|
|
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-
|
|
814
|
+
} from "./index-q9m97m5g.js";
|
|
815
815
|
import {
|
|
816
816
|
readV2ArchiveOffThread2
|
|
817
|
-
} from "./index-
|
|
817
|
+
} from "./index-0jc25yjf.js";
|
|
818
818
|
import {
|
|
819
819
|
renderSearchArchiveOffThread2
|
|
820
|
-
} from "./index-
|
|
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-
|
|
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-
|
|
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
|
-
|
|
24793
|
+
refusalCause;
|
|
24794
|
+
remedy;
|
|
24744
24795
|
code = "UNRESOLVED_HISTORY_BOUNDARY";
|
|
24745
24796
|
recoverable = true;
|
|
24746
|
-
constructor(estimatedTokens, contextLimitTokens,
|
|
24747
|
-
|
|
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.
|
|
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
|
-
|
|
25208
|
-
|
|
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
|
-
|
|
26317
|
-
|
|
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) {
|
|
@@ -63,18 +63,18 @@ import {
|
|
|
63
63
|
sanitizeFtsQuery,
|
|
64
64
|
searchMemoriesFTS,
|
|
65
65
|
searchMemoriesFTSUnion
|
|
66
|
-
} from "./index-
|
|
66
|
+
} from "./index-xqhejxmd.js";
|
|
67
67
|
import {
|
|
68
68
|
matchedSearchSnippet,
|
|
69
69
|
getIndexedMessageCorpusSize
|
|
70
|
-
} from "./index-
|
|
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-
|
|
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-
|
|
6
|
+
} from "./index-9gs34125.js";
|
|
7
7
|
import {
|
|
8
8
|
requestPendingMaterialization,
|
|
9
9
|
dropSlot
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-x7jcqpy6.js";
|
|
11
11
|
import {
|
|
12
12
|
executeContextRecomp
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-42n4fhxy.js";
|
|
14
14
|
import {
|
|
15
15
|
renderUserFacingFailure,
|
|
16
16
|
userFacingFailureCode
|
|
17
|
-
} from "./index-
|
|
17
|
+
} from "./index-xqhejxmd.js";
|
|
18
18
|
|
|
19
19
|
// src/hooks/magic-context/recomp-orchestrator.ts
|
|
20
20
|
function resolveLiveModelKey(liveSessionState, sessionId) {
|
|
@@ -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:
|
|
46
|
-
action: "
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
320
|
+
} from "./index-4xpff2m1.js";
|
|
321
321
|
import {
|
|
322
322
|
scheduleClearAndReindex
|
|
323
|
-
} from "./index-
|
|
323
|
+
} from "./index-g3j49m95.js";
|
|
324
324
|
import {
|
|
325
325
|
runManagedRecomp2
|
|
326
|
-
} from "./index-
|
|
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-
|
|
335
|
-
import"./index-
|
|
334
|
+
} from "./index-k2efzh9r.js";
|
|
335
|
+
import"./index-q9m97m5g.js";
|
|
336
336
|
import"./index-kaqs6h31.js";
|
|
337
|
-
import"./index-
|
|
338
|
-
import"./index-
|
|
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.
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
29
|
+
} from "./index-x4h461yf.js";
|
|
30
30
|
import"./index-2ny9xwdn.js";
|
|
31
31
|
import"./index-tad3can2.js";
|
|
32
32
|
|
package/dist/migration-worker.js
CHANGED
|
@@ -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-
|
|
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-
|
|
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-
|
|
84
|
+
import("./message-index-bounded-71b75npz.js"),
|
|
85
85
|
import("./sqlite-context-pragmas-mv9jqwjh.js")
|
|
86
86
|
]);
|
|
87
87
|
configureContextDatabasePragmas(db);
|