@cortexkit/opencode-magic-context 0.49.17 → 0.49.18
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-yhetp0kn.js → context-m897gfp9.js} +20 -11
- package/dist/features/magic-context/storage-host-instruction-retention.d.ts +11 -0
- package/dist/features/magic-context/storage-host-instruction-retention.d.ts.map +1 -0
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +22 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +4 -2
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/file-token-coverage.d.ts +11 -0
- package/dist/hooks/magic-context/file-token-coverage.d.ts.map +1 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +9 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/host-served-rows.d.ts +25 -0
- package/dist/hooks/magic-context/host-served-rows.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +7 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/pass-outcome.d.ts +2 -0
- package/dist/hooks/magic-context/pass-outcome.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +2 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/signed-thinking-hold.d.ts +59 -0
- package/dist/hooks/magic-context/signed-thinking-hold.d.ts.map +1 -0
- package/dist/hooks/magic-context/tag-content-primitives.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +6 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-context-state.d.ts +19 -0
- package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +19 -0
- 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/{index-5a1ex6x8.js → index-24jbw52d.js} +3 -3
- package/dist/{index-kmdj7dsq.js → index-6s5941tm.js} +1 -1
- package/dist/{index-aabzay3h.js → index-936py2wm.js} +207 -35
- package/dist/{index-hqhm3wke.js → index-cf74k5ak.js} +2 -2
- package/dist/{index-4yt7dtf4.js → index-e4xv8890.js} +90 -35
- package/dist/{index-fb2qxs2y.js → index-fgncb0ng.js} +1 -1
- package/dist/{index-nkpmm9q8.js → index-r4nkrs05.js} +2 -2
- package/dist/{index-p7m7j0cp.js → index-rmwykbbb.js} +38 -7
- package/dist/{index-a7c4r5re.js → index-s1ex9y6p.js} +55 -17
- package/dist/{index-vrzjhftj.js → index-s7j8tvhv.js} +2 -2
- package/dist/{index-cwzfcbtq.js → index-x4njr8df.js} +10 -1
- package/dist/index.js +14 -14
- package/dist/{message-index-dprebmtt.js → message-index-66jv6fh4.js} +3 -3
- package/dist/{message-index-bounded-1633vc7f.js → message-index-bounded-n1frdn85.js} +3 -3
- package/dist/migration-worker.js +1 -1
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-4zp09ejb.js → read-session-chunk-v06g3vka.js} +2 -2
- package/dist/{recomp-orchestrator-z3ecszx6.js → recomp-orchestrator-ghpk2dtq.js} +6 -6
- package/dist/{search-archive-znyy44ve.js → search-archive-4d53y23e.js} +3 -3
- package/dist/{search-6mee3vty.js → search-nkf271d4.js} +4 -4
- package/dist/{storage-tags-8qns3012.js → storage-tags-r7k9tjcv.js} +1 -1
- package/dist/{transform-postprocess-phase-3ydzxa62.js → transform-postprocess-phase-zpgav0h7.js} +6 -6
- package/dist/v2/auto-search-worker.js +1 -1
- package/dist/v2/chunk-embedding-write-worker.js +1 -1
- package/dist/v2/{context-jn3zpeqh.js → context-f2xh7ba4.js} +302 -68
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/{message-index-pxehjpzx.js → message-index-48f7hw7a.js} +3 -3
- package/dist/v2/{message-index-bounded-hpejqyd8.js → message-index-bounded-w3hfm29z.js} +3 -3
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-zdppn4bj.js → read-session-chunk-zpgmxwte.js} +2 -2
- package/dist/v2/{recomp-orchestrator-cmqnfpp3.js → recomp-orchestrator-4vfxej9t.js} +5 -5
- package/dist/v2/{search-archive-gfh11vs0.js → search-archive-vv48s2aa.js} +3 -3
- package/dist/v2/{search-66842dya.js → search-kza414f0.js} +4 -4
- package/dist/v2/{server-vsw8tmm6.js → server-1nyybqan.js} +2 -2
- package/dist/v2/{server-zyzawhdw.js → server-27gq4mfz.js} +2 -2
- package/dist/v2/{server-3rhpvy84.js → server-2ehj0bw7.js} +10 -1
- package/dist/v2/{server-gtfhttbr.js → server-a2eqhkxr.js} +1 -1
- package/dist/v2/{server-fw7wrk01.js → server-bfpda1tb.js} +55 -17
- package/dist/v2/{server-ec4ca92p.js → server-qv7f0hhe.js} +1 -1
- package/dist/v2/{server-kh7dpa1a.js → server-xhab8jx8.js} +38 -7
- package/dist/v2/server.js +2 -2
- package/dist/v2/{storage-tags-1h8k6ra9.js → storage-tags-3wdb8zph.js} +1 -1
- package/dist/v2/store-reader.d.ts +6 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{wrapup-orchestrator-xs8redz9.js → wrapup-orchestrator-psqz7yh0.js} +5 -5
- package/dist/{wrapup-orchestrator-j7d7ry5b.js → wrapup-orchestrator-s9zc5b00.js} +7 -7
- package/package.json +1 -1
|
@@ -144,7 +144,7 @@ import {
|
|
|
144
144
|
getDroppedTagsByNumbers2,
|
|
145
145
|
getMaxDroppedTagNumber2,
|
|
146
146
|
getTagById2
|
|
147
|
-
} from "./index-
|
|
147
|
+
} from "./index-cf74k5ak.js";
|
|
148
148
|
import {
|
|
149
149
|
observeTemporalDecisions,
|
|
150
150
|
stableStringify
|
|
@@ -179,6 +179,8 @@ import {
|
|
|
179
179
|
} from "./index-kq82mtg0.js";
|
|
180
180
|
import {
|
|
181
181
|
expandToolPart,
|
|
182
|
+
takeCoveredInstructionRows,
|
|
183
|
+
cloneKeepingCoveredInstructionMarks,
|
|
182
184
|
estimateTrueRawMessageTokens,
|
|
183
185
|
isTextPart,
|
|
184
186
|
toolPartHasUserAnswer,
|
|
@@ -268,6 +270,7 @@ import {
|
|
|
268
270
|
snapshotTrailingBlankSourceDecisions,
|
|
269
271
|
projectOpencodeReasoningBudgetCutoff,
|
|
270
272
|
resolveKeepReasoningTokens,
|
|
273
|
+
reasoningStepCost,
|
|
271
274
|
reasoningBudgetCutoff,
|
|
272
275
|
describeFinalWireTail,
|
|
273
276
|
estimateMessageTokens,
|
|
@@ -297,7 +300,7 @@ import {
|
|
|
297
300
|
readRawSessionMessageById2,
|
|
298
301
|
readSessionChunk2,
|
|
299
302
|
readRawSessionSeedTail2
|
|
300
|
-
} from "./index-
|
|
303
|
+
} from "./index-rmwykbbb.js";
|
|
301
304
|
import {
|
|
302
305
|
getMeasuredToolDefinitionTokens
|
|
303
306
|
} from "./index-ke416mdc.js";
|
|
@@ -314,7 +317,7 @@ import {
|
|
|
314
317
|
runSqliteOptimize,
|
|
315
318
|
openDatabase,
|
|
316
319
|
openCurrentDatabase
|
|
317
|
-
} from "./index-
|
|
320
|
+
} from "./index-fgncb0ng.js";
|
|
318
321
|
import {
|
|
319
322
|
registerOwnRpcServerInstance,
|
|
320
323
|
rpcPortDir,
|
|
@@ -367,6 +370,7 @@ import {
|
|
|
367
370
|
retryPendingSessionCleanups,
|
|
368
371
|
retryPendingRustSessionCleanupsForProject,
|
|
369
372
|
requestPendingMaterialization,
|
|
373
|
+
hasPendingMaterializationOrigin,
|
|
370
374
|
clearPendingMaterialization,
|
|
371
375
|
recordSystemPromptForRequest,
|
|
372
376
|
recordHeldHeadForRequest,
|
|
@@ -493,6 +497,7 @@ import {
|
|
|
493
497
|
onNoteTrigger,
|
|
494
498
|
clearNoteNudgeTriggerAndCooldown,
|
|
495
499
|
resetNoteNudgeCooldownOnly,
|
|
500
|
+
omitIncompleteFileTokenTotals,
|
|
496
501
|
RECOVERY_NO_HEAD_LIMIT,
|
|
497
502
|
deriveProtectedTailTokenTarget,
|
|
498
503
|
selectPerRunCap,
|
|
@@ -504,7 +509,7 @@ import {
|
|
|
504
509
|
snapRangeToCompartments,
|
|
505
510
|
getActiveCompartmentRun,
|
|
506
511
|
startCompartmentAgent
|
|
507
|
-
} from "./index-
|
|
512
|
+
} from "./index-s1ex9y6p.js";
|
|
508
513
|
import {
|
|
509
514
|
embedPauseBySession,
|
|
510
515
|
embedRunStateBySession,
|
|
@@ -562,7 +567,7 @@ import {
|
|
|
562
567
|
indexSingleMessage2,
|
|
563
568
|
indexMessagesAfterOrdinal2,
|
|
564
569
|
sweepOrphanedOpenCodeMessageIndexesCooperatively2
|
|
565
|
-
} from "./index-
|
|
570
|
+
} from "./index-x4njr8df.js";
|
|
566
571
|
import {
|
|
567
572
|
renderUserFacingFailure,
|
|
568
573
|
userFacingFailureCode,
|
|
@@ -670,7 +675,7 @@ import {
|
|
|
670
675
|
resolveMemoriesByIdsForSearch2,
|
|
671
676
|
unifiedSearch2,
|
|
672
677
|
formatSearchResults2
|
|
673
|
-
} from "./index-
|
|
678
|
+
} from "./index-s7j8tvhv.js";
|
|
674
679
|
import {
|
|
675
680
|
flushIgnoredMessages2,
|
|
676
681
|
clearIgnoredMessages2,
|
|
@@ -680,7 +685,7 @@ import {
|
|
|
680
685
|
import {
|
|
681
686
|
setRecompStarting2,
|
|
682
687
|
setRecompTerminal2
|
|
683
|
-
} from "./index-
|
|
688
|
+
} from "./index-r4nkrs05.js";
|
|
684
689
|
import {
|
|
685
690
|
makeToolCompositeKey,
|
|
686
691
|
searchMessageHistoryOffThread,
|
|
@@ -699,6 +704,7 @@ import {
|
|
|
699
704
|
resolveTodowriteAvailability,
|
|
700
705
|
canConsumeDeferredOnThisPass,
|
|
701
706
|
hasReclaimRide,
|
|
707
|
+
reclaimRidePermitted,
|
|
702
708
|
reclaimRideLabel,
|
|
703
709
|
captureOpencodeReasoningBudgetStatus,
|
|
704
710
|
reasoningBudgetStatusLine,
|
|
@@ -734,7 +740,7 @@ import {
|
|
|
734
740
|
abortSessionFailClosed2,
|
|
735
741
|
evaluateEmergencyFailClosed2,
|
|
736
742
|
runPostTransformPhase2
|
|
737
|
-
} from "./index-
|
|
743
|
+
} from "./index-e4xv8890.js";
|
|
738
744
|
import {
|
|
739
745
|
ANNOUNCEMENT_VERSION2,
|
|
740
746
|
ANNOUNCEMENT_FEATURES2,
|
|
@@ -747,7 +753,7 @@ import {
|
|
|
747
753
|
} from "./index-fmsr7v69.js";
|
|
748
754
|
import {
|
|
749
755
|
renderSearchArchiveOffThread2
|
|
750
|
-
} from "./index-
|
|
756
|
+
} from "./index-6s5941tm.js";
|
|
751
757
|
import {
|
|
752
758
|
COMPACTION_ENABLED_PATH,
|
|
753
759
|
isDreamerRunnable,
|
|
@@ -14076,8 +14082,9 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
14076
14082
|
const canClearReasoning = reasoningProjection?.canClearReasoning ?? modelAcceptsEmptyContent(reasoningProjection?.providerID);
|
|
14077
14083
|
const projectedPostDropPercentage = estimateProjectedPostDropPercentage(db, sessionId, usage, preloadedActiveTags ?? getActiveTagsBySession2(db, sessionId), keepReasoningTokens, sessionMeta.clearedReasoningThroughTag, canClearReasoning, reasoningProjection?.budgetCutoff, eligiblePendingDropTagIds);
|
|
14078
14084
|
const relativePostDropTarget = executeThresholdPercentage * POST_DROP_TARGET_RATIO;
|
|
14085
|
+
const ridePermitted = reclaimRide !== undefined && (reclaimRide.permission ? reclaimRidePermitted(reclaimRide, reclaimRide.permission) : hasReclaimRide(reclaimRide));
|
|
14079
14086
|
const rideLabel = reclaimRide ? reclaimRideLabel(reclaimRide) : "ride=none";
|
|
14080
|
-
const dropsCanLand =
|
|
14087
|
+
const dropsCanLand = ridePermitted;
|
|
14081
14088
|
const forceMaterializationPercentage = escalationBands(executeThresholdPercentage).forceMaterializationPercentage;
|
|
14082
14089
|
if (usage.percentage >= forceMaterializationPercentage) {
|
|
14083
14090
|
if (dropsCanLand && projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
@@ -16293,7 +16300,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16293
16300
|
const db = readDatabase();
|
|
16294
16301
|
if (!db)
|
|
16295
16302
|
return { ok: false, error: "db unavailable" };
|
|
16296
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
16303
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-ghpk2dtq.js"));
|
|
16297
16304
|
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-6ve0e8p4.js"));
|
|
16298
16305
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
16299
16306
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
@@ -16378,7 +16385,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16378
16385
|
const db = readDatabase();
|
|
16379
16386
|
if (!db)
|
|
16380
16387
|
return { ok: false, error: "db unavailable" };
|
|
16381
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
16388
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-s9zc5b00.js"));
|
|
16382
16389
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
16383
16390
|
const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
|
|
16384
16391
|
const ctx = {
|
|
@@ -17304,7 +17311,9 @@ var PASS_DEGRADATION_EFFECTS = {
|
|
|
17304
17311
|
"trailing-blank-decision-exception": "changes-request",
|
|
17305
17312
|
"proactive-thinking-strip-persistence-failure": "changes-request",
|
|
17306
17313
|
"reasoning-removal-read-failure": "changes-request",
|
|
17307
|
-
"reasoning-removal-persistence-failure": "changes-request"
|
|
17314
|
+
"reasoning-removal-persistence-failure": "changes-request",
|
|
17315
|
+
"host-instruction-retention-read-failure": "changes-request",
|
|
17316
|
+
"host-instruction-retention-persistence-failure": "changes-request"
|
|
17308
17317
|
};
|
|
17309
17318
|
function degradationChangesRequest(site) {
|
|
17310
17319
|
return PASS_DEGRADATION_EFFECTS[site] === "changes-request";
|
|
@@ -20175,6 +20184,24 @@ function contextUsagePassSnapshot(sessionMeta) {
|
|
|
20175
20184
|
} : null
|
|
20176
20185
|
};
|
|
20177
20186
|
}
|
|
20187
|
+
function savedProviderReadingForPass(input) {
|
|
20188
|
+
const persisted = input.persisted;
|
|
20189
|
+
if (!persisted)
|
|
20190
|
+
return null;
|
|
20191
|
+
const { percentage, inputTokens } = persisted.usage;
|
|
20192
|
+
if (!Number.isFinite(percentage) || percentage <= 0 || !Number.isFinite(inputTokens) || inputTokens <= 0) {
|
|
20193
|
+
return null;
|
|
20194
|
+
}
|
|
20195
|
+
if (!(input.lastResponseTime > 0) || input.cacheExpired)
|
|
20196
|
+
return null;
|
|
20197
|
+
if (persisted.lastObservedModelKey === null || input.currentModelKey === undefined || input.currentModelKey.length === 0 || piModelRefToCanonical(persisted.lastObservedModelKey) !== piModelRefToCanonical(input.currentModelKey)) {
|
|
20198
|
+
return null;
|
|
20199
|
+
}
|
|
20200
|
+
if (typeof input.contextLimit !== "number" || !(input.contextLimit > 0) || persisted.lastUsageContextLimit !== input.contextLimit) {
|
|
20201
|
+
return null;
|
|
20202
|
+
}
|
|
20203
|
+
return { percentage, inputTokens };
|
|
20204
|
+
}
|
|
20178
20205
|
function resolveUnknownUsageFromWireEstimate(input) {
|
|
20179
20206
|
if (input.usage.inputTokens > 0 || !input.pricedPass)
|
|
20180
20207
|
return input.usage;
|
|
@@ -23527,6 +23554,101 @@ function createRustModeTransform(deps, options) {
|
|
|
23527
23554
|
return adapter;
|
|
23528
23555
|
}
|
|
23529
23556
|
|
|
23557
|
+
// src/hooks/magic-context/signed-thinking-hold.ts
|
|
23558
|
+
var HEAVY_REASONING_TOKENS = 1500;
|
|
23559
|
+
var HEAVY_REASONING_WINDOW_STEPS = 15;
|
|
23560
|
+
var HOLD_CAP_POINTS = 10;
|
|
23561
|
+
var REASONING_TYPES = new Set(["reasoning", "thinking"]);
|
|
23562
|
+
function role(message) {
|
|
23563
|
+
if (!isRecord(message))
|
|
23564
|
+
return;
|
|
23565
|
+
return isRecord(message.info) ? message.info.role : message.role;
|
|
23566
|
+
}
|
|
23567
|
+
function parts(message) {
|
|
23568
|
+
if (!isRecord(message))
|
|
23569
|
+
return [];
|
|
23570
|
+
if (Array.isArray(message.parts))
|
|
23571
|
+
return message.parts;
|
|
23572
|
+
return Array.isArray(message.content) ? message.content : [];
|
|
23573
|
+
}
|
|
23574
|
+
function recordedReasoningTokens(message) {
|
|
23575
|
+
if (!isRecord(message))
|
|
23576
|
+
return;
|
|
23577
|
+
const info = isRecord(message.info) ? message.info : undefined;
|
|
23578
|
+
const candidates = [];
|
|
23579
|
+
if (info && isRecord(info.tokens))
|
|
23580
|
+
candidates.push(info.tokens.reasoning);
|
|
23581
|
+
if (isRecord(message.usage)) {
|
|
23582
|
+
candidates.push(message.usage.reasoning, message.usage.reasoningTokens);
|
|
23583
|
+
}
|
|
23584
|
+
for (const value of candidates) {
|
|
23585
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0)
|
|
23586
|
+
return value;
|
|
23587
|
+
}
|
|
23588
|
+
return;
|
|
23589
|
+
}
|
|
23590
|
+
function stepReasoningTokens(message, estimateTextTokens) {
|
|
23591
|
+
let text = "";
|
|
23592
|
+
let opaque = false;
|
|
23593
|
+
for (const part of parts(message)) {
|
|
23594
|
+
if (!isRecord(part))
|
|
23595
|
+
continue;
|
|
23596
|
+
const type = String(part.type ?? part.kind);
|
|
23597
|
+
if (type === "redacted_thinking" || part.redacted === true) {
|
|
23598
|
+
opaque = true;
|
|
23599
|
+
continue;
|
|
23600
|
+
}
|
|
23601
|
+
if (!REASONING_TYPES.has(type))
|
|
23602
|
+
continue;
|
|
23603
|
+
const body = typeof part.thinking === "string" ? part.thinking : typeof part.text === "string" ? part.text : "";
|
|
23604
|
+
if (body.length > 0)
|
|
23605
|
+
text += body;
|
|
23606
|
+
else
|
|
23607
|
+
opaque = true;
|
|
23608
|
+
}
|
|
23609
|
+
if (!text && !opaque)
|
|
23610
|
+
return 0;
|
|
23611
|
+
return reasoningStepCost(recordedReasoningTokens(message), text ? estimateTextTokens(text) : 0, opaque);
|
|
23612
|
+
}
|
|
23613
|
+
function decideSignedThinkingHold(args) {
|
|
23614
|
+
const capPercentage = args.executeThresholdPercentage + HOLD_CAP_POINTS;
|
|
23615
|
+
let heavyStepsBack = null;
|
|
23616
|
+
let heavyStepTokens = 0;
|
|
23617
|
+
const start = latestAssistantTurnStart(args.messages);
|
|
23618
|
+
let stepsBack = 0;
|
|
23619
|
+
for (let index = args.messages.length - 1;index >= start; index--) {
|
|
23620
|
+
const message = args.messages[index];
|
|
23621
|
+
if (role(message) !== "assistant" || parts(message).length === 0)
|
|
23622
|
+
continue;
|
|
23623
|
+
stepsBack++;
|
|
23624
|
+
if (stepsBack > HEAVY_REASONING_WINDOW_STEPS)
|
|
23625
|
+
break;
|
|
23626
|
+
const tokens = stepReasoningTokens(message, args.estimateTextTokens);
|
|
23627
|
+
if (tokens > HEAVY_REASONING_TOKENS) {
|
|
23628
|
+
heavyStepsBack = stepsBack;
|
|
23629
|
+
heavyStepTokens = tokens;
|
|
23630
|
+
break;
|
|
23631
|
+
}
|
|
23632
|
+
}
|
|
23633
|
+
if (heavyStepsBack === null)
|
|
23634
|
+
return {
|
|
23635
|
+
held: false,
|
|
23636
|
+
reason: "no_recent_heavy_reasoning",
|
|
23637
|
+
heavyStepsBack,
|
|
23638
|
+
heavyStepTokens,
|
|
23639
|
+
capPercentage
|
|
23640
|
+
};
|
|
23641
|
+
if (!(args.usagePercentage < capPercentage))
|
|
23642
|
+
return { held: false, reason: "above_cap", heavyStepsBack, heavyStepTokens, capPercentage };
|
|
23643
|
+
return {
|
|
23644
|
+
held: true,
|
|
23645
|
+
reason: "heavy_reasoning",
|
|
23646
|
+
heavyStepsBack,
|
|
23647
|
+
heavyStepTokens,
|
|
23648
|
+
capPercentage
|
|
23649
|
+
};
|
|
23650
|
+
}
|
|
23651
|
+
|
|
23530
23652
|
// src/hooks/magic-context/temporal-served-projection.ts
|
|
23531
23653
|
function readLkgTemporalDecisions(db, sessionId, runtime) {
|
|
23532
23654
|
const slot = getInMemorySlot(sessionId) ?? loadPersistedLkgSlot(db, sessionId);
|
|
@@ -23750,7 +23872,7 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
23750
23872
|
justAwaitedPublication = activeRun.published;
|
|
23751
23873
|
published = published || activeRun.published;
|
|
23752
23874
|
const historyReprepareShouldBust = activeRun.published && args.deferredHistoryRefreshSessions.has(args.sessionId);
|
|
23753
|
-
pendingCompartmentInjection = prepareCompartmentInjection(args.db, args.resolvedSessionId, args.messages, historyReprepareShouldBust, args.projectPath, args.injectionBudgetTokens, args.experimentalTemporalAwareness);
|
|
23875
|
+
pendingCompartmentInjection = prepareCompartmentInjection(args.db, args.resolvedSessionId, args.messages, historyReprepareShouldBust, args.coveredInstructions, args.projectPath, args.injectionBudgetTokens, args.experimentalTemporalAwareness);
|
|
23754
23876
|
if (historyReprepareShouldBust) {
|
|
23755
23877
|
rebuiltHistoryThisPass = true;
|
|
23756
23878
|
}
|
|
@@ -24050,7 +24172,8 @@ function createTransform(deps) {
|
|
|
24050
24172
|
const startTime = performance.now();
|
|
24051
24173
|
const historianRun = deps.resolveHistorianRun?.();
|
|
24052
24174
|
const messages = output.messages;
|
|
24053
|
-
const originalForThinkingFit = messages.some((message) => message.parts.some((part) => isRecord(part) && ["reasoning", "thinking", "redacted_thinking"].includes(String(part.type)))) ?
|
|
24175
|
+
const originalForThinkingFit = messages.some((message) => message.parts.some((part) => isRecord(part) && ["reasoning", "thinking", "redacted_thinking"].includes(String(part.type)))) ? cloneKeepingCoveredInstructionMarks(messages) : null;
|
|
24176
|
+
const coveredHostInstructions = takeCoveredInstructionRows(messages);
|
|
24054
24177
|
const passOutcome = createPassOutcome();
|
|
24055
24178
|
const tSessionId = performance.now();
|
|
24056
24179
|
const sessionId = findSessionId(messages);
|
|
@@ -24248,8 +24371,8 @@ function createTransform(deps) {
|
|
|
24248
24371
|
return true;
|
|
24249
24372
|
}
|
|
24250
24373
|
})();
|
|
24251
|
-
let activeThinkingPrefixHold =
|
|
24252
|
-
let freezeM0M1 = unresolvedDirectoryHold
|
|
24374
|
+
let activeThinkingPrefixHold = false;
|
|
24375
|
+
let freezeM0M1 = unresolvedDirectoryHold;
|
|
24253
24376
|
const compartmentDirectory = sessionDirectory;
|
|
24254
24377
|
const historianRunnable = deps.historianRunnable !== false;
|
|
24255
24378
|
const canRunCompartments = fullFeatureMode && !compactionOff && historianRunnable && (deps.client !== undefined || deps.hiddenCompletionExecutor !== undefined) && compartmentDirectory.length > 0;
|
|
@@ -24377,13 +24500,7 @@ function createTransform(deps) {
|
|
|
24377
24500
|
}
|
|
24378
24501
|
const resolvedProviderID = modelForBudget?.providerID;
|
|
24379
24502
|
activeThinkingTurn ||= hasActiveAnthropicThinkingTurn(messages, resolvedProviderID, modelForBudget?.modelID);
|
|
24380
|
-
|
|
24381
|
-
freezeM0M1 ||= activeThinkingPrefixHold;
|
|
24382
|
-
if (freezeM0M1 && prefixHoldLogTurnIds.get(sessionId) !== currentTurnId) {
|
|
24383
|
-
prefixHoldLogTurnIds.set(sessionId, currentTurnId);
|
|
24384
|
-
const reason = activeThinkingPrefixHold ? "active thinking turn (prefix-bound model)" : "session directory unresolved";
|
|
24385
|
-
sessionLog2(sessionId, `m[0]/m[1] frozen: ${reason}; replaying the frozen prefix and deferring any rebuild`);
|
|
24386
|
-
}
|
|
24503
|
+
const signedThinkingPrefixBound = activeThinkingTurn && (isPrefixBoundThinkingModel(activeThinkingModel?.providerID, activeThinkingModel?.modelID) || isPrefixBoundThinkingModel(resolvedProviderID, modelForBudget?.modelID));
|
|
24387
24504
|
const canUseEmptySentinels = modelAcceptsEmptyContent(resolvedProviderID);
|
|
24388
24505
|
const protectedThinkingMessages = activeThinkingTurn || isAnthropicFamilyRoute(resolvedProviderID, modelForBudget?.modelID) ? latestAssistantTurnMessages(messages) : new Set;
|
|
24389
24506
|
const resolvedContextLimit = modelForBudget ? resolveTrustedContextLimit(modelForBudget.providerID, modelForBudget.modelID, {
|
|
@@ -24437,6 +24554,29 @@ function createTransform(deps) {
|
|
|
24437
24554
|
const effectiveExecuteThresholdPercentage = executeThresholdDetail.percentage;
|
|
24438
24555
|
sessionLog2(sessionId, `transform threshold: model=${currentModelKeyForBoundary ?? "unknown"} matchedModel=${executeThresholdDetail.matchedKey ?? "scalar"} mode=${executeThresholdDetail.mode} threshold=${effectiveExecuteThresholdPercentage}% proactiveFloor=${getProactiveCompartmentTriggerPercentage(effectiveExecuteThresholdPercentage)}%`);
|
|
24439
24556
|
const { forceMaterializationPercentage } = escalationBands(effectiveExecuteThresholdPercentage);
|
|
24557
|
+
let holdProseRatio;
|
|
24558
|
+
const signedThinkingHold = signedThinkingPrefixBound ? decideSignedThinkingHold({
|
|
24559
|
+
messages,
|
|
24560
|
+
usagePercentage: contextUsageEarly.percentage,
|
|
24561
|
+
executeThresholdPercentage: effectiveExecuteThresholdPercentage,
|
|
24562
|
+
estimateTextTokens: (text) => {
|
|
24563
|
+
holdProseRatio ??= sessionDecisionCalibration(db, sessionId).proseRatio;
|
|
24564
|
+
return estimateTokens(text) * holdProseRatio;
|
|
24565
|
+
}
|
|
24566
|
+
}) : null;
|
|
24567
|
+
activeThinkingPrefixHold = signedThinkingPrefixBound && (compactionOff || signedThinkingHold?.held === true);
|
|
24568
|
+
freezeM0M1 ||= activeThinkingPrefixHold;
|
|
24569
|
+
const prefixHoldLogKey = signedThinkingHold ? `${currentTurnId}:${signedThinkingHold.reason}:${signedThinkingHold.heavyStepsBack ?? "none"}` : freezeM0M1 ? `${currentTurnId}:directory` : null;
|
|
24570
|
+
if (prefixHoldLogKey !== null && prefixHoldLogTurnIds.get(sessionId) !== prefixHoldLogKey) {
|
|
24571
|
+
prefixHoldLogTurnIds.set(sessionId, prefixHoldLogKey);
|
|
24572
|
+
if (signedThinkingHold) {
|
|
24573
|
+
sessionLog2(sessionId, `signed thinking hold: held=${signedThinkingHold.held} reason=${signedThinkingHold.reason} heavyStepsBack=${signedThinkingHold.heavyStepsBack ?? "none"} heavyStepTokens=${signedThinkingHold.heavyStepTokens} usage=${contextUsageEarly.percentage.toFixed(1)}% cap=${signedThinkingHold.capPercentage}%`);
|
|
24574
|
+
}
|
|
24575
|
+
if (freezeM0M1) {
|
|
24576
|
+
const reason = activeThinkingPrefixHold ? compactionOff ? "active thinking turn in compaction-off mode (prefix-bound model)" : "recent heavy reasoning in the active thinking turn (prefix-bound model)" : "session directory unresolved";
|
|
24577
|
+
sessionLog2(sessionId, `m[0]/m[1] frozen: ${reason}; replaying the frozen prefix and deferring any rebuild`);
|
|
24578
|
+
}
|
|
24579
|
+
}
|
|
24440
24580
|
const persistedUsageFreshForBoundary = persistedUsageBeforeResets && Date.now() - persistedUsageBeforeResets.updatedAt <= 10 * 60 * 1000 && (persistedUsageBeforeResets.lastObservedModelKey === null || currentModelKeyForBoundary === undefined || piModelRefToCanonical(persistedUsageBeforeResets.lastObservedModelKey) === piModelRefToCanonical(currentModelKeyForBoundary)) && (resolvedContextLimit === undefined || persistedUsageBeforeResets.lastUsageContextLimit === 0 || persistedUsageBeforeResets.lastUsageContextLimit === resolvedContextLimit) ? persistedUsageBeforeResets.usage : null;
|
|
24441
24581
|
const boundaryUsageForProtectedTail = persistedUsageFreshForBoundary ?? contextUsageEarly;
|
|
24442
24582
|
const boundaryUsageSource = persistedUsageFreshForBoundary ? "persisted" : "live";
|
|
@@ -24623,8 +24763,14 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24623
24763
|
}, {
|
|
24624
24764
|
hardFold: false,
|
|
24625
24765
|
force: contextUsageEarly.percentage >= forceMaterializationPercentage && (contextUsageEarly.percentage >= 95 || getEmergencyInputSample(db, sessionId) === 0),
|
|
24626
|
-
explicitFlush: deps.pendingMaterializationSessions
|
|
24627
|
-
publishedHistory: isCacheBusting
|
|
24766
|
+
explicitFlush: hasPendingMaterializationOrigin(deps.pendingMaterializationSessions, sessionId, "user_flush"),
|
|
24767
|
+
publishedHistory: isCacheBusting,
|
|
24768
|
+
permission: {
|
|
24769
|
+
signedThinkingHold: activeThinkingPrefixHold,
|
|
24770
|
+
firstRender: false,
|
|
24771
|
+
idleExpiry: false,
|
|
24772
|
+
emergency: contextUsageEarly.percentage >= forceMaterializationPercentage
|
|
24773
|
+
}
|
|
24628
24774
|
}, pendingDropEligibility.read(sessionId, dropProjectionKey()));
|
|
24629
24775
|
if (triggerResult.shouldFire) {
|
|
24630
24776
|
sessionLog2(sessionId, `compartment trigger: firing (reason=${triggerResult.reason})`);
|
|
@@ -24644,7 +24790,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24644
24790
|
const messagesBeforeInitialPrepare = isCacheBusting && deferredHistoryWasPendingAtPassStart ? [...messages] : null;
|
|
24645
24791
|
if (fullFeatureMode && !compactionOff) {
|
|
24646
24792
|
const tInj = performance.now();
|
|
24647
|
-
pendingCompartmentInjection = prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, projectIdentity, deps.memoryConfig?.injectionBudgetTokens, deps.experimentalTemporalAwareness);
|
|
24793
|
+
pendingCompartmentInjection = prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, coveredHostInstructions, projectIdentity, deps.memoryConfig?.injectionBudgetTokens, deps.experimentalTemporalAwareness);
|
|
24648
24794
|
if (messagesBeforeInitialPrepare) {
|
|
24649
24795
|
const skippedVisibleMessages = pendingCompartmentInjection?.skippedVisibleMessages ?? 0;
|
|
24650
24796
|
trimmedMessagesAtCompactionBoundary = messagesBeforeInitialPrepare.slice(0, skippedVisibleMessages);
|
|
@@ -24818,6 +24964,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24818
24964
|
fallbackModels: historianRun?.fallbackModels ?? deps.fallbackModels,
|
|
24819
24965
|
compartmentDirectory,
|
|
24820
24966
|
messages,
|
|
24967
|
+
coveredInstructions: coveredHostInstructions,
|
|
24821
24968
|
pendingCompartmentInjection,
|
|
24822
24969
|
fallbackModelId,
|
|
24823
24970
|
projectPath: projectIdentity,
|
|
@@ -24889,30 +25036,53 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24889
25036
|
bustReason: calibrationBustReason,
|
|
24890
25037
|
onAdopt: (message) => sessionLog2(sessionId, message)
|
|
24891
25038
|
});
|
|
25039
|
+
let contextUsageFromEstimate = false;
|
|
24892
25040
|
if (contextUsage.inputTokens <= 0 && protectionCacheBustingPass) {
|
|
25041
|
+
const overflowRecoveryPass = usagePercentageSynthetic || emergencyRecoveryArmed;
|
|
25042
|
+
const savedProviderReading = overflowRecoveryPass ? null : savedProviderReadingForPass({
|
|
25043
|
+
persisted: persistedUsageBeforeResets,
|
|
25044
|
+
currentModelKey: currentModelKeyForBoundary ?? (hardModelKey || undefined),
|
|
25045
|
+
contextLimit: resolvedContextLimit,
|
|
25046
|
+
lastResponseTime: sessionMeta.lastResponseTime,
|
|
25047
|
+
cacheExpired: hardCacheExpired
|
|
25048
|
+
});
|
|
25049
|
+
let pressureEstimate;
|
|
24893
25050
|
try {
|
|
24894
|
-
|
|
25051
|
+
pressureEstimate = estimateFinalWireInputTokens({
|
|
24895
25052
|
messages,
|
|
24896
25053
|
systemPromptTokens: sessionMeta.systemPromptTokens,
|
|
24897
25054
|
providerID: modelForBudget?.providerID,
|
|
24898
25055
|
modelID: modelForBudget?.modelID,
|
|
24899
25056
|
agentName: notificationParams.agent
|
|
24900
25057
|
});
|
|
25058
|
+
} catch (error) {
|
|
25059
|
+
sessionLog2(sessionId, `transform: wire-estimate pressure fallback unavailable: ${getErrorMessage(error)}`);
|
|
25060
|
+
}
|
|
25061
|
+
const usableHard = windowGeometry?.usableHard;
|
|
25062
|
+
const countPercentage = pressureEstimate?.pressureTokens !== undefined && Number.isFinite(pressureEstimate.pressureTokens) && typeof usableHard === "number" && usableHard > 0 ? pressureEstimate.pressureTokens / usableHard * 100 : 0;
|
|
25063
|
+
const grewPastSavedReading = savedProviderReading !== null && countPercentage >= 95 && countPercentage > savedProviderReading.percentage;
|
|
25064
|
+
if (savedProviderReading && !grewPastSavedReading) {
|
|
25065
|
+
contextUsage = {
|
|
25066
|
+
inputTokens: savedProviderReading.inputTokens,
|
|
25067
|
+
percentage: Math.max(contextUsage.percentage, savedProviderReading.percentage)
|
|
25068
|
+
};
|
|
25069
|
+
sessionLog2(sessionId, `transform: unknown provider usage; using saved provider reading for priced pass inputTokens=${contextUsage.inputTokens} percentage=${contextUsage.percentage.toFixed(1)} countPercentage=${countPercentage.toFixed(1)}`);
|
|
25070
|
+
} else if (pressureEstimate) {
|
|
25071
|
+
const percentageBeforeEstimate = contextUsage.percentage;
|
|
24901
25072
|
contextUsage = resolveUnknownUsageFromWireEstimate({
|
|
24902
25073
|
usage: contextUsage,
|
|
24903
25074
|
pricedPass: true,
|
|
24904
|
-
wireEstimateTokens: pressureEstimate.tokens,
|
|
25075
|
+
wireEstimateTokens: overflowRecoveryPass ? pressureEstimate.tokens : pressureEstimate.pressureTokens,
|
|
24905
25076
|
wireEstimateTrusted: pressureEstimate.trusted,
|
|
24906
25077
|
providerProvenInputTokens: providerProvenInputForRecovery,
|
|
24907
25078
|
providerProvenLimitTokens: providerProvenLimitForRecovery,
|
|
24908
|
-
usableHardLimit:
|
|
25079
|
+
usableHardLimit: usableHard
|
|
24909
25080
|
});
|
|
24910
25081
|
if (contextUsage.inputTokens > 0) {
|
|
24911
25082
|
const usedProviderInput = !pressureEstimate.trusted && providerProvenLimitForRecovery !== undefined && providerProvenInputForRecovery !== undefined && contextUsage.inputTokens >= providerProvenInputForRecovery;
|
|
24912
|
-
|
|
25083
|
+
contextUsageFromEstimate = !overflowRecoveryPass && !usedProviderInput && !usagePercentageSynthetic && contextUsage.percentage > percentageBeforeEstimate;
|
|
25084
|
+
sessionLog2(sessionId, `transform: unknown provider usage; using ${usedProviderInput ? "provider-proven input" : "wire estimate"} for priced pass inputTokens=${contextUsage.inputTokens} percentage=${contextUsage.percentage.toFixed(1)} trusted=${pressureEstimate.trusted} wireTokens=${pressureEstimate.tokens} pressureTokens=${pressureEstimate.pressureTokens}${grewPastSavedReading ? ` grewPastSavedReading=${savedProviderReading?.percentage.toFixed(1)}` : ""}`);
|
|
24913
25085
|
}
|
|
24914
|
-
} catch (error) {
|
|
24915
|
-
sessionLog2(sessionId, `transform: wire-estimate pressure fallback unavailable: ${getErrorMessage(error)}`);
|
|
24916
25086
|
}
|
|
24917
25087
|
}
|
|
24918
25088
|
const protectionUsableSoft = windowGeometry?.usableSoft ?? boundaryContextLimit;
|
|
@@ -24953,6 +25123,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24953
25123
|
activeAgent,
|
|
24954
25124
|
batch,
|
|
24955
25125
|
contextUsage,
|
|
25126
|
+
contextUsageFromEstimate,
|
|
24956
25127
|
usableWindow: resolvedContextLimit ?? 0,
|
|
24957
25128
|
schedulerDecision,
|
|
24958
25129
|
schedulerDeferReason,
|
|
@@ -24998,6 +25169,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24998
25169
|
emergencyCeilingTokens,
|
|
24999
25170
|
pendingCompartmentInjection,
|
|
25000
25171
|
prefixTrimSourceOrder,
|
|
25172
|
+
coveredHostInstructions,
|
|
25001
25173
|
hiddenMessagesAtCompactionSeam,
|
|
25002
25174
|
trimmedMessagesAtCompactionBoundary,
|
|
25003
25175
|
didMutateFromFlushedStatuses,
|
|
@@ -25198,7 +25370,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25198
25370
|
if (!finalWireEstimate) {
|
|
25199
25371
|
sessionLog2(sessionId, `transform: final-wire telemetry estimate=unavailable trusted=false conversation=unknown tools=unknown system=unknown toolDefinitions=unknown tail=${finalWireTail}`);
|
|
25200
25372
|
}
|
|
25201
|
-
finishSystemDateRefresh(deps.historyRefreshSessions, dateRequest, postTransformResult.bustedThisPass && !activeThinkingPrefixHold || postTransformResult.thinkingReleasedForFit === true);
|
|
25373
|
+
finishSystemDateRefresh(deps.historyRefreshSessions, dateRequest, postTransformResult.bustedThisPass && !activeThinkingPrefixHold && postTransformResult.openTurnSignedThinkingKept !== true || postTransformResult.thinkingReleasedForFit === true);
|
|
25202
25374
|
if (activeThinkingPrefixHold && !postTransformResult.thinkingReleasedForFit && sessionMeta.cachedM0Bytes != null && sessionMeta.cachedM1Bytes != null) {
|
|
25203
25375
|
recordHeldHeadForRequest(sessionId, currentLkgRequestIdentity(sessionId), (ownsHistory) => deferDeliveredSystemRefresh(deps, sessionId, ownsHistory));
|
|
25204
25376
|
}
|
|
@@ -25299,7 +25471,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25299
25471
|
});
|
|
25300
25472
|
if (uncachedMessageIds.length > 0) {
|
|
25301
25473
|
try {
|
|
25302
|
-
storedByMessage = getActiveTagTokenTotalsByMessage2(db, sessionId, uncachedMessageIds);
|
|
25474
|
+
storedByMessage = omitIncompleteFileTokenTotals(db, sessionId, messages.flatMap((message) => message.info.id ? [{ id: message.info.id, parts: message.parts }] : []), getActiveTagTokenTotalsByMessage2(db, sessionId, uncachedMessageIds));
|
|
25303
25475
|
} catch {
|
|
25304
25476
|
storedByMessage = new Map;
|
|
25305
25477
|
}
|
|
@@ -68,8 +68,8 @@ function protectedToolTokenCount(tags, counts, calibration) {
|
|
|
68
68
|
var encoder = new TextEncoder;
|
|
69
69
|
var TAG_PREFIX_REGEX = /^(?:§\d+§\s*)+/;
|
|
70
70
|
var MALFORMED_TAG_PREFIX_REGEX = /^(?:§\d+">§(?:\d+§)?\s*)+/;
|
|
71
|
-
var DANGLING_TAG_GLOBAL_REGEX = /\u00a7\d+(?!\.\d)[^\s\u00a7\w.]?/g;
|
|
72
|
-
var DANGLING_TAG_PREFIX_REGEX = /^(?:\u00a7\d+(?!\.\d)[^\s\u00a7\w.]?\s*)+/;
|
|
71
|
+
var DANGLING_TAG_GLOBAL_REGEX = /\u00a7\d+(?!\d)(?!\.\d)[^\s\u00a7\w.]?/g;
|
|
72
|
+
var DANGLING_TAG_PREFIX_REGEX = /^(?:\u00a7\d+(?!\d)(?!\.\d)[^\s\u00a7\w.]?\s*)+/;
|
|
73
73
|
var COMPLETE_TAG_PAIR_GLOBAL_REGEX = /\u00a7\d+\u00a7/g;
|
|
74
74
|
var MALFORMED_TAG_GLOBAL_REGEX = /\u00a7\d+">(?:\u00a7(?:\d+\u00a7)?)?/g;
|
|
75
75
|
var STRAY_SECTION_CHAR_REGEX = /\u00a7/g;
|