@cortexkit/opencode-magic-context 0.49.17 → 0.49.19
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 +6 -2
- package/dist/chunk-embedding-write-worker.js +2 -2
- package/dist/{context-yhetp0kn.js → context-j31m2dv7.js} +27 -14
- package/dist/features/magic-context/dreamer/classify.d.ts +3 -0
- package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts +11 -0
- package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/map-memories.d.ts +3 -0
- package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts +3 -0
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/storage-clone.d.ts.map +1 -1
- 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/features/magic-context/storage-meta-persisted.d.ts +13 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-worker-evaluation.fixture.d.ts +2 -0
- package/dist/hooks/magic-context/auto-search-worker-evaluation.fixture.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/hook.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-recovery-prefix.d.ts +13 -0
- package/dist/hooks/magic-context/lkg-recovery-prefix.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/system-date-refresh.d.ts +15 -2
- package/dist/hooks/magic-context/system-date-refresh.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- 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 +21 -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-aabzay3h.js → index-3esx8tkf.js} +256 -50
- package/dist/{index-v8awdgvd.js → index-3h4dp9wb.js} +1 -1
- package/dist/{index-5a1ex6x8.js → index-4911rn0b.js} +3 -3
- package/dist/{index-qn7xstt2.js → index-63k48rv9.js} +1 -2
- package/dist/{index-p7m7j0cp.js → index-9zcsy3hh.js} +53 -7
- package/dist/{index-nkpmm9q8.js → index-c1p88z1y.js} +3 -3
- package/dist/{index-hqhm3wke.js → index-cf74k5ak.js} +2 -2
- package/dist/{index-vrzjhftj.js → index-dxmq29t1.js} +4 -4
- package/dist/{index-kmdj7dsq.js → index-edmpdxcw.js} +1 -1
- package/dist/{index-4yt7dtf4.js → index-jhghdnsm.js} +113 -44
- package/dist/{index-fb2qxs2y.js → index-jrr131e0.js} +2 -2
- package/dist/{index-a7c4r5re.js → index-rpxdjkm0.js} +216 -40
- package/dist/{index-cwzfcbtq.js → index-se4m2g6w.js} +10 -1
- package/dist/index.js +21 -17
- package/dist/{message-index-bounded-1633vc7f.js → message-index-bounded-zyc8h32y.js} +3 -3
- package/dist/{message-index-dprebmtt.js → message-index-gtpqnj8w.js} +3 -3
- package/dist/migration-worker.js +2 -2
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-4zp09ejb.js → read-session-chunk-jjb48bt9.js} +2 -2
- package/dist/{recomp-orchestrator-z3ecszx6.js → recomp-orchestrator-999jj4bc.js} +8 -8
- package/dist/{search-archive-znyy44ve.js → search-archive-6vm0e2f5.js} +3 -3
- package/dist/{search-6mee3vty.js → search-xsqk1bj4.js} +6 -6
- package/dist/shared/model-suggestion-retry.d.ts +30 -1
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/shared/prompt-async-transport.d.ts.map +1 -1
- package/dist/{storage-tags-8qns3012.js → storage-tags-r7k9tjcv.js} +1 -1
- package/dist/tools/ctx-expand/rust-mode-tag.test-support.d.ts +15 -0
- package/dist/tools/ctx-expand/rust-mode-tag.test-support.d.ts.map +1 -0
- package/dist/tools/ctx-expand/tools.d.ts +11 -0
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-3ydzxa62.js → transform-postprocess-phase-jj99r7z2.js} +8 -8
- package/dist/v2/auto-search-worker.js +6 -2
- package/dist/v2/chunk-embedding-write-worker.js +2 -2
- package/dist/v2/{context-jn3zpeqh.js → context-y5yamxak.js} +378 -92
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/hooks/tools.d.ts.map +1 -1
- package/dist/v2/{message-index-pxehjpzx.js → message-index-8vz2pq76.js} +3 -3
- package/dist/v2/{message-index-bounded-hpejqyd8.js → message-index-bounded-spd8r7pj.js} +3 -3
- package/dist/v2/migration-worker.js +2 -2
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-zdppn4bj.js → read-session-chunk-cwkxrmns.js} +2 -2
- package/dist/v2/{recomp-orchestrator-cmqnfpp3.js → recomp-orchestrator-f6m9jr7p.js} +7 -7
- package/dist/v2/{search-archive-gfh11vs0.js → search-archive-wve3tq1k.js} +3 -3
- package/dist/v2/{search-66842dya.js → search-hwg7jfbj.js} +6 -6
- package/dist/v2/{server-zyzawhdw.js → server-27gq4mfz.js} +2 -2
- package/dist/v2/{server-3rhpvy84.js → server-2ar62dyx.js} +10 -1
- package/dist/v2/{server-ec4ca92p.js → server-45q69hkq.js} +1 -1
- package/dist/v2/{server-fw7wrk01.js → server-6vdzn1td.js} +216 -40
- package/dist/v2/{server-kh7dpa1a.js → server-9hx7g5jp.js} +53 -7
- package/dist/v2/{server-gtfhttbr.js → server-bmymkx73.js} +2 -2
- package/dist/v2/{server-vsw8tmm6.js → server-gsxjv2q2.js} +4 -4
- package/dist/v2/{server-my7k4eds.js → server-hm38q7r0.js} +1 -1
- package/dist/v2/{server-gpvay0xz.js → server-xq7dfjke.js} +1 -2
- 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-embdz8gj.js} +7 -7
- package/dist/{wrapup-orchestrator-j7d7ry5b.js → wrapup-orchestrator-whhbjmaz.js} +9 -9
- package/package.json +1 -1
- package/src/shared/model-suggestion-retry.test.ts +166 -0
- package/src/shared/model-suggestion-retry.ts +165 -14
- package/src/shared/prompt-async-transport.test.ts +107 -0
- package/src/shared/prompt-async-transport.ts +39 -0
|
@@ -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-9zcsy3hh.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-jrr131e0.js";
|
|
318
321
|
import {
|
|
319
322
|
registerOwnRpcServerInstance,
|
|
320
323
|
rpcPortDir,
|
|
@@ -333,7 +336,7 @@ import {
|
|
|
333
336
|
resolveStoredPathWorkspaceIdentity,
|
|
334
337
|
storedPathBelongsToWorkspace,
|
|
335
338
|
computeWorkspaceEpochFingerprint
|
|
336
|
-
} from "./index-
|
|
339
|
+
} from "./index-63k48rv9.js";
|
|
337
340
|
import {
|
|
338
341
|
V2_MEMORY_CATEGORIES,
|
|
339
342
|
CATEGORY_PRIORITY
|
|
@@ -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,
|
|
@@ -393,6 +397,8 @@ import {
|
|
|
393
397
|
hasProcessLocalLkgProof,
|
|
394
398
|
lkgDirtyRevision,
|
|
395
399
|
rememberLkgDirtyRevision,
|
|
400
|
+
readPersistedLkgUntaggedInputIds,
|
|
401
|
+
persistLkgUntaggedInputIds,
|
|
396
402
|
noteLkgRecoveryPrefix,
|
|
397
403
|
readLkgRecoveryPrefix,
|
|
398
404
|
noteLkgHealthyPrefix,
|
|
@@ -493,6 +499,7 @@ import {
|
|
|
493
499
|
onNoteTrigger,
|
|
494
500
|
clearNoteNudgeTriggerAndCooldown,
|
|
495
501
|
resetNoteNudgeCooldownOnly,
|
|
502
|
+
omitIncompleteFileTokenTotals,
|
|
496
503
|
RECOVERY_NO_HEAD_LIMIT,
|
|
497
504
|
deriveProtectedTailTokenTarget,
|
|
498
505
|
selectPerRunCap,
|
|
@@ -504,7 +511,7 @@ import {
|
|
|
504
511
|
snapRangeToCompartments,
|
|
505
512
|
getActiveCompartmentRun,
|
|
506
513
|
startCompartmentAgent
|
|
507
|
-
} from "./index-
|
|
514
|
+
} from "./index-rpxdjkm0.js";
|
|
508
515
|
import {
|
|
509
516
|
embedPauseBySession,
|
|
510
517
|
embedRunStateBySession,
|
|
@@ -562,7 +569,7 @@ import {
|
|
|
562
569
|
indexSingleMessage2,
|
|
563
570
|
indexMessagesAfterOrdinal2,
|
|
564
571
|
sweepOrphanedOpenCodeMessageIndexesCooperatively2
|
|
565
|
-
} from "./index-
|
|
572
|
+
} from "./index-se4m2g6w.js";
|
|
566
573
|
import {
|
|
567
574
|
renderUserFacingFailure,
|
|
568
575
|
userFacingFailureCode,
|
|
@@ -606,7 +613,7 @@ import {
|
|
|
606
613
|
readGitFileChangeTimesSince,
|
|
607
614
|
verificationFileExists,
|
|
608
615
|
normalizeVerificationFiles
|
|
609
|
-
} from "./index-
|
|
616
|
+
} from "./index-3h4dp9wb.js";
|
|
610
617
|
import {
|
|
611
618
|
registerNotificationSink2,
|
|
612
619
|
pushNotification2,
|
|
@@ -670,7 +677,7 @@ import {
|
|
|
670
677
|
resolveMemoriesByIdsForSearch2,
|
|
671
678
|
unifiedSearch2,
|
|
672
679
|
formatSearchResults2
|
|
673
|
-
} from "./index-
|
|
680
|
+
} from "./index-dxmq29t1.js";
|
|
674
681
|
import {
|
|
675
682
|
flushIgnoredMessages2,
|
|
676
683
|
clearIgnoredMessages2,
|
|
@@ -680,7 +687,7 @@ import {
|
|
|
680
687
|
import {
|
|
681
688
|
setRecompStarting2,
|
|
682
689
|
setRecompTerminal2
|
|
683
|
-
} from "./index-
|
|
690
|
+
} from "./index-c1p88z1y.js";
|
|
684
691
|
import {
|
|
685
692
|
makeToolCompositeKey,
|
|
686
693
|
searchMessageHistoryOffThread,
|
|
@@ -699,6 +706,7 @@ import {
|
|
|
699
706
|
resolveTodowriteAvailability,
|
|
700
707
|
canConsumeDeferredOnThisPass,
|
|
701
708
|
hasReclaimRide,
|
|
709
|
+
reclaimRidePermitted,
|
|
702
710
|
reclaimRideLabel,
|
|
703
711
|
captureOpencodeReasoningBudgetStatus,
|
|
704
712
|
reasoningBudgetStatusLine,
|
|
@@ -734,7 +742,7 @@ import {
|
|
|
734
742
|
abortSessionFailClosed2,
|
|
735
743
|
evaluateEmergencyFailClosed2,
|
|
736
744
|
runPostTransformPhase2
|
|
737
|
-
} from "./index-
|
|
745
|
+
} from "./index-jhghdnsm.js";
|
|
738
746
|
import {
|
|
739
747
|
ANNOUNCEMENT_VERSION2,
|
|
740
748
|
ANNOUNCEMENT_FEATURES2,
|
|
@@ -747,7 +755,7 @@ import {
|
|
|
747
755
|
} from "./index-fmsr7v69.js";
|
|
748
756
|
import {
|
|
749
757
|
renderSearchArchiveOffThread2
|
|
750
|
-
} from "./index-
|
|
758
|
+
} from "./index-edmpdxcw.js";
|
|
751
759
|
import {
|
|
752
760
|
COMPACTION_ENABLED_PATH,
|
|
753
761
|
isDreamerRunnable,
|
|
@@ -2855,6 +2863,7 @@ async function applyCuesThroughModule(args, chunk, manifestText, signal) {
|
|
|
2855
2863
|
}
|
|
2856
2864
|
|
|
2857
2865
|
// src/features/magic-context/dreamer/hidden-single-shot.ts
|
|
2866
|
+
var DREAMER_FIRST_OUTPUT_TIMEOUT_MS = 90000;
|
|
2858
2867
|
async function runHiddenSingleShotPrompt(args) {
|
|
2859
2868
|
const system = withContentLanguageDirective(args.system, args.language);
|
|
2860
2869
|
const opening = args.executor.open({
|
|
@@ -2896,6 +2905,7 @@ async function runHiddenSingleShotPrompt(args) {
|
|
|
2896
2905
|
}, {
|
|
2897
2906
|
transport: Object.assign((request) => args.executor.attempt(handle, request), { childSessionId: handle.childSessionId }),
|
|
2898
2907
|
timeoutMs: args.timeoutMs,
|
|
2908
|
+
...args.firstOutputTimeoutMs !== undefined ? { firstOutputTimeoutMs: args.firstOutputTimeoutMs } : {},
|
|
2899
2909
|
...args.signal ? { signal: args.signal } : {},
|
|
2900
2910
|
fallbackModels: args.fallbackModels,
|
|
2901
2911
|
callContext: args.callContext,
|
|
@@ -3550,6 +3560,7 @@ async function classifyOneChunk(args, chunk, anchors, sliceMs, signal) {
|
|
|
3550
3560
|
}, {
|
|
3551
3561
|
transport: Object.assign((request) => executor.attempt(opened, request), { childSessionId: opened.childSessionId }),
|
|
3552
3562
|
timeoutMs: sliceMs,
|
|
3563
|
+
firstOutputTimeoutMs: args.firstOutputTimeoutMs ?? DREAMER_FIRST_OUTPUT_TIMEOUT_MS,
|
|
3553
3564
|
signal,
|
|
3554
3565
|
fallbackModels: args.fallbackModels,
|
|
3555
3566
|
callContext: "dreamer:classify-memories",
|
|
@@ -7218,6 +7229,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7218
7229
|
model: args.model,
|
|
7219
7230
|
fallbackModels: args.fallbackModels,
|
|
7220
7231
|
timeoutMs: sliceMs,
|
|
7232
|
+
firstOutputTimeoutMs: args.firstOutputTimeoutMs ?? DREAMER_FIRST_OUTPUT_TIMEOUT_MS,
|
|
7221
7233
|
signal,
|
|
7222
7234
|
onOpened: () => {
|
|
7223
7235
|
stage = "prompt";
|
|
@@ -7272,6 +7284,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
7272
7284
|
onBudgetUpdate
|
|
7273
7285
|
}),
|
|
7274
7286
|
timeoutMs: sliceMs,
|
|
7287
|
+
firstOutputTimeoutMs: args.firstOutputTimeoutMs ?? DREAMER_FIRST_OUTPUT_TIMEOUT_MS,
|
|
7275
7288
|
signal,
|
|
7276
7289
|
fallbackModels: args.fallbackModels,
|
|
7277
7290
|
callContext: "dreamer:map-memories",
|
|
@@ -9205,6 +9218,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
9205
9218
|
fallbackModels: args.fallbackModels,
|
|
9206
9219
|
language: args.language,
|
|
9207
9220
|
timeoutMs: sliceMs,
|
|
9221
|
+
firstOutputTimeoutMs: args.firstOutputTimeoutMs ?? DREAMER_FIRST_OUTPUT_TIMEOUT_MS,
|
|
9208
9222
|
signal: batchSignal,
|
|
9209
9223
|
onFailureOutput: (completion) => {
|
|
9210
9224
|
failedCompletion = completion;
|
|
@@ -9262,6 +9276,7 @@ async function verifyOneBatch(args, batch, sliceMs, signal) {
|
|
|
9262
9276
|
onBudgetUpdate
|
|
9263
9277
|
}),
|
|
9264
9278
|
timeoutMs: sliceMs,
|
|
9279
|
+
firstOutputTimeoutMs: args.firstOutputTimeoutMs ?? DREAMER_FIRST_OUTPUT_TIMEOUT_MS,
|
|
9265
9280
|
signal: batchSignal,
|
|
9266
9281
|
fallbackModels: args.fallbackModels,
|
|
9267
9282
|
callContext: "dreamer:verify",
|
|
@@ -14076,8 +14091,9 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
14076
14091
|
const canClearReasoning = reasoningProjection?.canClearReasoning ?? modelAcceptsEmptyContent(reasoningProjection?.providerID);
|
|
14077
14092
|
const projectedPostDropPercentage = estimateProjectedPostDropPercentage(db, sessionId, usage, preloadedActiveTags ?? getActiveTagsBySession2(db, sessionId), keepReasoningTokens, sessionMeta.clearedReasoningThroughTag, canClearReasoning, reasoningProjection?.budgetCutoff, eligiblePendingDropTagIds);
|
|
14078
14093
|
const relativePostDropTarget = executeThresholdPercentage * POST_DROP_TARGET_RATIO;
|
|
14094
|
+
const ridePermitted = reclaimRide !== undefined && (reclaimRide.permission ? reclaimRidePermitted(reclaimRide, reclaimRide.permission) : hasReclaimRide(reclaimRide));
|
|
14079
14095
|
const rideLabel = reclaimRide ? reclaimRideLabel(reclaimRide) : "ride=none";
|
|
14080
|
-
const dropsCanLand =
|
|
14096
|
+
const dropsCanLand = ridePermitted;
|
|
14081
14097
|
const forceMaterializationPercentage = escalationBands(executeThresholdPercentage).forceMaterializationPercentage;
|
|
14082
14098
|
if (usage.percentage >= forceMaterializationPercentage) {
|
|
14083
14099
|
if (dropsCanLand && projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
@@ -16293,7 +16309,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16293
16309
|
const db = readDatabase();
|
|
16294
16310
|
if (!db)
|
|
16295
16311
|
return { ok: false, error: "db unavailable" };
|
|
16296
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
16312
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-999jj4bc.js"));
|
|
16297
16313
|
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-6ve0e8p4.js"));
|
|
16298
16314
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
16299
16315
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
@@ -16378,7 +16394,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
16378
16394
|
const db = readDatabase();
|
|
16379
16395
|
if (!db)
|
|
16380
16396
|
return { ok: false, error: "db unavailable" };
|
|
16381
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
16397
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-whhbjmaz.js"));
|
|
16382
16398
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
16383
16399
|
const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
|
|
16384
16400
|
const ctx = {
|
|
@@ -17304,7 +17320,9 @@ var PASS_DEGRADATION_EFFECTS = {
|
|
|
17304
17320
|
"trailing-blank-decision-exception": "changes-request",
|
|
17305
17321
|
"proactive-thinking-strip-persistence-failure": "changes-request",
|
|
17306
17322
|
"reasoning-removal-read-failure": "changes-request",
|
|
17307
|
-
"reasoning-removal-persistence-failure": "changes-request"
|
|
17323
|
+
"reasoning-removal-persistence-failure": "changes-request",
|
|
17324
|
+
"host-instruction-retention-read-failure": "changes-request",
|
|
17325
|
+
"host-instruction-retention-persistence-failure": "changes-request"
|
|
17308
17326
|
};
|
|
17309
17327
|
function degradationChangesRequest(site) {
|
|
17310
17328
|
return PASS_DEGRADATION_EFFECTS[site] === "changes-request";
|
|
@@ -20175,6 +20193,24 @@ function contextUsagePassSnapshot(sessionMeta) {
|
|
|
20175
20193
|
} : null
|
|
20176
20194
|
};
|
|
20177
20195
|
}
|
|
20196
|
+
function savedProviderReadingForPass(input) {
|
|
20197
|
+
const persisted = input.persisted;
|
|
20198
|
+
if (!persisted)
|
|
20199
|
+
return null;
|
|
20200
|
+
const { percentage, inputTokens } = persisted.usage;
|
|
20201
|
+
if (!Number.isFinite(percentage) || percentage <= 0 || !Number.isFinite(inputTokens) || inputTokens <= 0) {
|
|
20202
|
+
return null;
|
|
20203
|
+
}
|
|
20204
|
+
if (!(input.lastResponseTime > 0) || input.cacheExpired)
|
|
20205
|
+
return null;
|
|
20206
|
+
if (persisted.lastObservedModelKey === null || input.currentModelKey === undefined || input.currentModelKey.length === 0 || piModelRefToCanonical(persisted.lastObservedModelKey) !== piModelRefToCanonical(input.currentModelKey)) {
|
|
20207
|
+
return null;
|
|
20208
|
+
}
|
|
20209
|
+
if (typeof input.contextLimit !== "number" || !(input.contextLimit > 0) || persisted.lastUsageContextLimit !== input.contextLimit) {
|
|
20210
|
+
return null;
|
|
20211
|
+
}
|
|
20212
|
+
return { percentage, inputTokens };
|
|
20213
|
+
}
|
|
20178
20214
|
function resolveUnknownUsageFromWireEstimate(input) {
|
|
20179
20215
|
if (input.usage.inputTokens > 0 || !input.pricedPass)
|
|
20180
20216
|
return input.usage;
|
|
@@ -20303,6 +20339,7 @@ function beginSystemDateRequest(history, sessionId, stage, turnId, identity) {
|
|
|
20303
20339
|
systemDone: false,
|
|
20304
20340
|
messagesSeen: false,
|
|
20305
20341
|
permitted: undefined,
|
|
20342
|
+
signedThinkingKept: undefined,
|
|
20306
20343
|
ambiguous: identity === undefined && (turnId === undefined || sameTurn)
|
|
20307
20344
|
};
|
|
20308
20345
|
const blocked = [...requests.values()].filter((candidate) => !candidate.explicit && candidate.ambiguous && !(candidate.systemSeen && candidate.messagesSeen) && candidate.turnId === turnId).length;
|
|
@@ -20325,6 +20362,10 @@ function systemDateRefreshPermission(history, request) {
|
|
|
20325
20362
|
const current = state(history, request);
|
|
20326
20363
|
return current?.ambiguous ? undefined : current?.permitted;
|
|
20327
20364
|
}
|
|
20365
|
+
function systemDateSignedThinkingKept(history, request) {
|
|
20366
|
+
const current = state(history, request);
|
|
20367
|
+
return current?.ambiguous ? undefined : current?.signedThinkingKept;
|
|
20368
|
+
}
|
|
20328
20369
|
function waitForSystemDateRefresh(history, request, apply) {
|
|
20329
20370
|
const current = state(history, request);
|
|
20330
20371
|
if (!current)
|
|
@@ -20339,7 +20380,7 @@ function retire(history, current) {
|
|
|
20339
20380
|
if (unpairable) {
|
|
20340
20381
|
const apply = current.waiting;
|
|
20341
20382
|
current.waiting = undefined;
|
|
20342
|
-
apply?.(false);
|
|
20383
|
+
apply?.(false, undefined);
|
|
20343
20384
|
}
|
|
20344
20385
|
const channel = channels.get(history);
|
|
20345
20386
|
const requests = channel?.get(current.sessionId);
|
|
@@ -20347,14 +20388,15 @@ function retire(history, current) {
|
|
|
20347
20388
|
if (requests?.size === 0)
|
|
20348
20389
|
channel?.delete(current.sessionId);
|
|
20349
20390
|
}
|
|
20350
|
-
function finishSystemDateRefresh(history, request, permitted) {
|
|
20391
|
+
function finishSystemDateRefresh(history, request, permitted, signedThinkingKept) {
|
|
20351
20392
|
const current = state(history, request);
|
|
20352
20393
|
if (!current)
|
|
20353
20394
|
return;
|
|
20354
20395
|
current.permitted = current.ambiguous ? false : permitted;
|
|
20396
|
+
current.signedThinkingKept = current.ambiguous ? undefined : signedThinkingKept;
|
|
20355
20397
|
const apply = current.waiting;
|
|
20356
20398
|
current.waiting = undefined;
|
|
20357
|
-
apply?.(current.permitted);
|
|
20399
|
+
apply?.(current.permitted, current.signedThinkingKept);
|
|
20358
20400
|
retire(history, current);
|
|
20359
20401
|
}
|
|
20360
20402
|
function finishSystemDateHook(history, request) {
|
|
@@ -23527,6 +23569,101 @@ function createRustModeTransform(deps, options) {
|
|
|
23527
23569
|
return adapter;
|
|
23528
23570
|
}
|
|
23529
23571
|
|
|
23572
|
+
// src/hooks/magic-context/signed-thinking-hold.ts
|
|
23573
|
+
var HEAVY_REASONING_TOKENS = 1500;
|
|
23574
|
+
var HEAVY_REASONING_WINDOW_STEPS = 15;
|
|
23575
|
+
var HOLD_CAP_POINTS = 10;
|
|
23576
|
+
var REASONING_TYPES = new Set(["reasoning", "thinking"]);
|
|
23577
|
+
function role(message) {
|
|
23578
|
+
if (!isRecord(message))
|
|
23579
|
+
return;
|
|
23580
|
+
return isRecord(message.info) ? message.info.role : message.role;
|
|
23581
|
+
}
|
|
23582
|
+
function parts(message) {
|
|
23583
|
+
if (!isRecord(message))
|
|
23584
|
+
return [];
|
|
23585
|
+
if (Array.isArray(message.parts))
|
|
23586
|
+
return message.parts;
|
|
23587
|
+
return Array.isArray(message.content) ? message.content : [];
|
|
23588
|
+
}
|
|
23589
|
+
function recordedReasoningTokens(message) {
|
|
23590
|
+
if (!isRecord(message))
|
|
23591
|
+
return;
|
|
23592
|
+
const info = isRecord(message.info) ? message.info : undefined;
|
|
23593
|
+
const candidates = [];
|
|
23594
|
+
if (info && isRecord(info.tokens))
|
|
23595
|
+
candidates.push(info.tokens.reasoning);
|
|
23596
|
+
if (isRecord(message.usage)) {
|
|
23597
|
+
candidates.push(message.usage.reasoning, message.usage.reasoningTokens);
|
|
23598
|
+
}
|
|
23599
|
+
for (const value of candidates) {
|
|
23600
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0)
|
|
23601
|
+
return value;
|
|
23602
|
+
}
|
|
23603
|
+
return;
|
|
23604
|
+
}
|
|
23605
|
+
function stepReasoningTokens(message, estimateTextTokens) {
|
|
23606
|
+
let text = "";
|
|
23607
|
+
let opaque = false;
|
|
23608
|
+
for (const part of parts(message)) {
|
|
23609
|
+
if (!isRecord(part))
|
|
23610
|
+
continue;
|
|
23611
|
+
const type = String(part.type ?? part.kind);
|
|
23612
|
+
if (type === "redacted_thinking" || part.redacted === true) {
|
|
23613
|
+
opaque = true;
|
|
23614
|
+
continue;
|
|
23615
|
+
}
|
|
23616
|
+
if (!REASONING_TYPES.has(type))
|
|
23617
|
+
continue;
|
|
23618
|
+
const body = typeof part.thinking === "string" ? part.thinking : typeof part.text === "string" ? part.text : "";
|
|
23619
|
+
if (body.length > 0)
|
|
23620
|
+
text += body;
|
|
23621
|
+
else
|
|
23622
|
+
opaque = true;
|
|
23623
|
+
}
|
|
23624
|
+
if (!text && !opaque)
|
|
23625
|
+
return 0;
|
|
23626
|
+
return reasoningStepCost(recordedReasoningTokens(message), text ? estimateTextTokens(text) : 0, opaque);
|
|
23627
|
+
}
|
|
23628
|
+
function decideSignedThinkingHold(args) {
|
|
23629
|
+
const capPercentage = args.executeThresholdPercentage + HOLD_CAP_POINTS;
|
|
23630
|
+
let heavyStepsBack = null;
|
|
23631
|
+
let heavyStepTokens = 0;
|
|
23632
|
+
const start = latestAssistantTurnStart(args.messages);
|
|
23633
|
+
let stepsBack = 0;
|
|
23634
|
+
for (let index = args.messages.length - 1;index >= start; index--) {
|
|
23635
|
+
const message = args.messages[index];
|
|
23636
|
+
if (role(message) !== "assistant" || parts(message).length === 0)
|
|
23637
|
+
continue;
|
|
23638
|
+
stepsBack++;
|
|
23639
|
+
if (stepsBack > HEAVY_REASONING_WINDOW_STEPS)
|
|
23640
|
+
break;
|
|
23641
|
+
const tokens = stepReasoningTokens(message, args.estimateTextTokens);
|
|
23642
|
+
if (tokens > HEAVY_REASONING_TOKENS) {
|
|
23643
|
+
heavyStepsBack = stepsBack;
|
|
23644
|
+
heavyStepTokens = tokens;
|
|
23645
|
+
break;
|
|
23646
|
+
}
|
|
23647
|
+
}
|
|
23648
|
+
if (heavyStepsBack === null)
|
|
23649
|
+
return {
|
|
23650
|
+
held: false,
|
|
23651
|
+
reason: "no_recent_heavy_reasoning",
|
|
23652
|
+
heavyStepsBack,
|
|
23653
|
+
heavyStepTokens,
|
|
23654
|
+
capPercentage
|
|
23655
|
+
};
|
|
23656
|
+
if (!(args.usagePercentage < capPercentage))
|
|
23657
|
+
return { held: false, reason: "above_cap", heavyStepsBack, heavyStepTokens, capPercentage };
|
|
23658
|
+
return {
|
|
23659
|
+
held: true,
|
|
23660
|
+
reason: "heavy_reasoning",
|
|
23661
|
+
heavyStepsBack,
|
|
23662
|
+
heavyStepTokens,
|
|
23663
|
+
capPercentage
|
|
23664
|
+
};
|
|
23665
|
+
}
|
|
23666
|
+
|
|
23530
23667
|
// src/hooks/magic-context/temporal-served-projection.ts
|
|
23531
23668
|
function readLkgTemporalDecisions(db, sessionId, runtime) {
|
|
23532
23669
|
const slot = getInMemorySlot(sessionId) ?? loadPersistedLkgSlot(db, sessionId);
|
|
@@ -23750,7 +23887,7 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
23750
23887
|
justAwaitedPublication = activeRun.published;
|
|
23751
23888
|
published = published || activeRun.published;
|
|
23752
23889
|
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);
|
|
23890
|
+
pendingCompartmentInjection = prepareCompartmentInjection(args.db, args.resolvedSessionId, args.messages, historyReprepareShouldBust, args.coveredInstructions, args.projectPath, args.injectionBudgetTokens, args.experimentalTemporalAwareness);
|
|
23754
23891
|
if (historyReprepareShouldBust) {
|
|
23755
23892
|
rebuiltHistoryThisPass = true;
|
|
23756
23893
|
}
|
|
@@ -24050,7 +24187,8 @@ function createTransform(deps) {
|
|
|
24050
24187
|
const startTime = performance.now();
|
|
24051
24188
|
const historianRun = deps.resolveHistorianRun?.();
|
|
24052
24189
|
const messages = output.messages;
|
|
24053
|
-
const originalForThinkingFit = messages.some((message) => message.parts.some((part) => isRecord(part) && ["reasoning", "thinking", "redacted_thinking"].includes(String(part.type)))) ?
|
|
24190
|
+
const originalForThinkingFit = messages.some((message) => message.parts.some((part) => isRecord(part) && ["reasoning", "thinking", "redacted_thinking"].includes(String(part.type)))) ? cloneKeepingCoveredInstructionMarks(messages) : null;
|
|
24191
|
+
const coveredHostInstructions = takeCoveredInstructionRows(messages);
|
|
24054
24192
|
const passOutcome = createPassOutcome();
|
|
24055
24193
|
const tSessionId = performance.now();
|
|
24056
24194
|
const sessionId = findSessionId(messages);
|
|
@@ -24066,6 +24204,11 @@ function createTransform(deps) {
|
|
|
24066
24204
|
const tLkgEntry = performance.now();
|
|
24067
24205
|
const lkgInput = deps.transformMode === "rust" ? [] : projectEntry(sessionId, messages);
|
|
24068
24206
|
const recovery = deps.compactionOff || deps.transformMode === "rust" ? {} : readLkgRecoveryPrefix(sessionId, lkgInput, messages, deps.db);
|
|
24207
|
+
const persistedUntaggedInputIds = deps.compactionOff || deps.transformMode === "rust" ? [] : readPersistedLkgUntaggedInputIds(deps.db, sessionId);
|
|
24208
|
+
const untaggedReplayIds = new Set([
|
|
24209
|
+
...recovery.prefix?.untaggedInputIds ?? [],
|
|
24210
|
+
...persistedUntaggedInputIds
|
|
24211
|
+
]);
|
|
24069
24212
|
logTransformTiming(sessionId, "lkg.entryProjection", tLkgEntry, deps.transformMode === "rust" || !entryReuse ? undefined : `reused=${entryReuse.reused} retained=${entryReuse.retained} retainedBytes=${entryReuse.retainedBytes}`);
|
|
24070
24213
|
const resolvedSessionId = sessionId;
|
|
24071
24214
|
const runNotificationParams = (sid) => {
|
|
@@ -24248,8 +24391,8 @@ function createTransform(deps) {
|
|
|
24248
24391
|
return true;
|
|
24249
24392
|
}
|
|
24250
24393
|
})();
|
|
24251
|
-
let activeThinkingPrefixHold =
|
|
24252
|
-
let freezeM0M1 = unresolvedDirectoryHold
|
|
24394
|
+
let activeThinkingPrefixHold = false;
|
|
24395
|
+
let freezeM0M1 = unresolvedDirectoryHold;
|
|
24253
24396
|
const compartmentDirectory = sessionDirectory;
|
|
24254
24397
|
const historianRunnable = deps.historianRunnable !== false;
|
|
24255
24398
|
const canRunCompartments = fullFeatureMode && !compactionOff && historianRunnable && (deps.client !== undefined || deps.hiddenCompletionExecutor !== undefined) && compartmentDirectory.length > 0;
|
|
@@ -24377,13 +24520,7 @@ function createTransform(deps) {
|
|
|
24377
24520
|
}
|
|
24378
24521
|
const resolvedProviderID = modelForBudget?.providerID;
|
|
24379
24522
|
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
|
-
}
|
|
24523
|
+
const signedThinkingPrefixBound = activeThinkingTurn && (isPrefixBoundThinkingModel(activeThinkingModel?.providerID, activeThinkingModel?.modelID) || isPrefixBoundThinkingModel(resolvedProviderID, modelForBudget?.modelID));
|
|
24387
24524
|
const canUseEmptySentinels = modelAcceptsEmptyContent(resolvedProviderID);
|
|
24388
24525
|
const protectedThinkingMessages = activeThinkingTurn || isAnthropicFamilyRoute(resolvedProviderID, modelForBudget?.modelID) ? latestAssistantTurnMessages(messages) : new Set;
|
|
24389
24526
|
const resolvedContextLimit = modelForBudget ? resolveTrustedContextLimit(modelForBudget.providerID, modelForBudget.modelID, {
|
|
@@ -24437,6 +24574,29 @@ function createTransform(deps) {
|
|
|
24437
24574
|
const effectiveExecuteThresholdPercentage = executeThresholdDetail.percentage;
|
|
24438
24575
|
sessionLog2(sessionId, `transform threshold: model=${currentModelKeyForBoundary ?? "unknown"} matchedModel=${executeThresholdDetail.matchedKey ?? "scalar"} mode=${executeThresholdDetail.mode} threshold=${effectiveExecuteThresholdPercentage}% proactiveFloor=${getProactiveCompartmentTriggerPercentage(effectiveExecuteThresholdPercentage)}%`);
|
|
24439
24576
|
const { forceMaterializationPercentage } = escalationBands(effectiveExecuteThresholdPercentage);
|
|
24577
|
+
let holdProseRatio;
|
|
24578
|
+
const signedThinkingHold = signedThinkingPrefixBound ? decideSignedThinkingHold({
|
|
24579
|
+
messages,
|
|
24580
|
+
usagePercentage: contextUsageEarly.percentage,
|
|
24581
|
+
executeThresholdPercentage: effectiveExecuteThresholdPercentage,
|
|
24582
|
+
estimateTextTokens: (text) => {
|
|
24583
|
+
holdProseRatio ??= sessionDecisionCalibration(db, sessionId).proseRatio;
|
|
24584
|
+
return estimateTokens(text) * holdProseRatio;
|
|
24585
|
+
}
|
|
24586
|
+
}) : null;
|
|
24587
|
+
activeThinkingPrefixHold = signedThinkingPrefixBound && (compactionOff || signedThinkingHold?.held === true);
|
|
24588
|
+
freezeM0M1 ||= activeThinkingPrefixHold;
|
|
24589
|
+
const prefixHoldLogKey = signedThinkingHold ? `${currentTurnId}:${signedThinkingHold.reason}:${signedThinkingHold.heavyStepsBack ?? "none"}` : freezeM0M1 ? `${currentTurnId}:directory` : null;
|
|
24590
|
+
if (prefixHoldLogKey !== null && prefixHoldLogTurnIds.get(sessionId) !== prefixHoldLogKey) {
|
|
24591
|
+
prefixHoldLogTurnIds.set(sessionId, prefixHoldLogKey);
|
|
24592
|
+
if (signedThinkingHold) {
|
|
24593
|
+
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}%`);
|
|
24594
|
+
}
|
|
24595
|
+
if (freezeM0M1) {
|
|
24596
|
+
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";
|
|
24597
|
+
sessionLog2(sessionId, `m[0]/m[1] frozen: ${reason}; replaying the frozen prefix and deferring any rebuild`);
|
|
24598
|
+
}
|
|
24599
|
+
}
|
|
24440
24600
|
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
24601
|
const boundaryUsageForProtectedTail = persistedUsageFreshForBoundary ?? contextUsageEarly;
|
|
24442
24602
|
const boundaryUsageSource = persistedUsageFreshForBoundary ? "persisted" : "live";
|
|
@@ -24623,8 +24783,14 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24623
24783
|
}, {
|
|
24624
24784
|
hardFold: false,
|
|
24625
24785
|
force: contextUsageEarly.percentage >= forceMaterializationPercentage && (contextUsageEarly.percentage >= 95 || getEmergencyInputSample(db, sessionId) === 0),
|
|
24626
|
-
explicitFlush: deps.pendingMaterializationSessions
|
|
24627
|
-
publishedHistory: isCacheBusting
|
|
24786
|
+
explicitFlush: hasPendingMaterializationOrigin(deps.pendingMaterializationSessions, sessionId, "user_flush"),
|
|
24787
|
+
publishedHistory: isCacheBusting,
|
|
24788
|
+
permission: {
|
|
24789
|
+
signedThinkingHold: activeThinkingPrefixHold,
|
|
24790
|
+
firstRender: false,
|
|
24791
|
+
idleExpiry: false,
|
|
24792
|
+
emergency: contextUsageEarly.percentage >= forceMaterializationPercentage
|
|
24793
|
+
}
|
|
24628
24794
|
}, pendingDropEligibility.read(sessionId, dropProjectionKey()));
|
|
24629
24795
|
if (triggerResult.shouldFire) {
|
|
24630
24796
|
sessionLog2(sessionId, `compartment trigger: firing (reason=${triggerResult.reason})`);
|
|
@@ -24644,7 +24810,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24644
24810
|
const messagesBeforeInitialPrepare = isCacheBusting && deferredHistoryWasPendingAtPassStart ? [...messages] : null;
|
|
24645
24811
|
if (fullFeatureMode && !compactionOff) {
|
|
24646
24812
|
const tInj = performance.now();
|
|
24647
|
-
pendingCompartmentInjection = prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, projectIdentity, deps.memoryConfig?.injectionBudgetTokens, deps.experimentalTemporalAwareness);
|
|
24813
|
+
pendingCompartmentInjection = prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, coveredHostInstructions, projectIdentity, deps.memoryConfig?.injectionBudgetTokens, deps.experimentalTemporalAwareness);
|
|
24648
24814
|
if (messagesBeforeInitialPrepare) {
|
|
24649
24815
|
const skippedVisibleMessages = pendingCompartmentInjection?.skippedVisibleMessages ?? 0;
|
|
24650
24816
|
trimmedMessagesAtCompactionBoundary = messagesBeforeInitialPrepare.slice(0, skippedVisibleMessages);
|
|
@@ -24676,10 +24842,11 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24676
24842
|
let taggingSucceeded = false;
|
|
24677
24843
|
let recoveryBatch = null;
|
|
24678
24844
|
let recoveryNormalized = false;
|
|
24679
|
-
const
|
|
24845
|
+
const untaggedReplayTailServed = !!recovery.prefix || untaggedReplayIds.size > 0 && messages.some((message) => untaggedReplayIds.has(message.info.id ?? ""));
|
|
24846
|
+
const normalizeRecoveryTail = untaggedReplayTailServed ? () => {
|
|
24680
24847
|
if (recoveryNormalized)
|
|
24681
24848
|
return;
|
|
24682
|
-
const tail = messages.filter((message) =>
|
|
24849
|
+
const tail = messages.filter((message) => untaggedReplayIds.has(message.info.id ?? ""));
|
|
24683
24850
|
const tagged = tagMessages(sessionId, tail, deps.tagger, db, {
|
|
24684
24851
|
skipPrefixInjection: !ctxReduceCallable,
|
|
24685
24852
|
servedMessages: messages,
|
|
@@ -24705,7 +24872,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24705
24872
|
const messagesForTagging = messagesBeforeInitialPrepare && hiddenMessagesAtCompactionSeam.length > 0 ? messagesBeforeInitialPrepare : messages;
|
|
24706
24873
|
const canAdoptScopedToolSweep = isCacheBusting || canConsumeDeferredEarly;
|
|
24707
24874
|
const scopedToolSweep = useScopedToolSweep(db, sessionId, canAdoptScopedToolSweep) ? true : createPreAdoptionToolSweepResolver(db, sessionId);
|
|
24708
|
-
const result = tagMessages(sessionId,
|
|
24875
|
+
const result = tagMessages(sessionId, untaggedReplayIds.size > 0 ? messagesForTagging.filter((message) => !untaggedReplayIds.has(message.info.id ?? "")) : messagesForTagging, deps.tagger, db, {
|
|
24709
24876
|
skipPrefixInjection,
|
|
24710
24877
|
scopedToolSweep,
|
|
24711
24878
|
servedMessages: messages,
|
|
@@ -24818,6 +24985,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24818
24985
|
fallbackModels: historianRun?.fallbackModels ?? deps.fallbackModels,
|
|
24819
24986
|
compartmentDirectory,
|
|
24820
24987
|
messages,
|
|
24988
|
+
coveredInstructions: coveredHostInstructions,
|
|
24821
24989
|
pendingCompartmentInjection,
|
|
24822
24990
|
fallbackModelId,
|
|
24823
24991
|
projectPath: projectIdentity,
|
|
@@ -24889,30 +25057,53 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24889
25057
|
bustReason: calibrationBustReason,
|
|
24890
25058
|
onAdopt: (message) => sessionLog2(sessionId, message)
|
|
24891
25059
|
});
|
|
25060
|
+
let contextUsageFromEstimate = false;
|
|
24892
25061
|
if (contextUsage.inputTokens <= 0 && protectionCacheBustingPass) {
|
|
25062
|
+
const overflowRecoveryPass = usagePercentageSynthetic || emergencyRecoveryArmed;
|
|
25063
|
+
const savedProviderReading = overflowRecoveryPass ? null : savedProviderReadingForPass({
|
|
25064
|
+
persisted: persistedUsageBeforeResets,
|
|
25065
|
+
currentModelKey: currentModelKeyForBoundary ?? (hardModelKey || undefined),
|
|
25066
|
+
contextLimit: resolvedContextLimit,
|
|
25067
|
+
lastResponseTime: sessionMeta.lastResponseTime,
|
|
25068
|
+
cacheExpired: hardCacheExpired
|
|
25069
|
+
});
|
|
25070
|
+
let pressureEstimate;
|
|
24893
25071
|
try {
|
|
24894
|
-
|
|
25072
|
+
pressureEstimate = estimateFinalWireInputTokens({
|
|
24895
25073
|
messages,
|
|
24896
25074
|
systemPromptTokens: sessionMeta.systemPromptTokens,
|
|
24897
25075
|
providerID: modelForBudget?.providerID,
|
|
24898
25076
|
modelID: modelForBudget?.modelID,
|
|
24899
25077
|
agentName: notificationParams.agent
|
|
24900
25078
|
});
|
|
25079
|
+
} catch (error) {
|
|
25080
|
+
sessionLog2(sessionId, `transform: wire-estimate pressure fallback unavailable: ${getErrorMessage(error)}`);
|
|
25081
|
+
}
|
|
25082
|
+
const usableHard = windowGeometry?.usableHard;
|
|
25083
|
+
const countPercentage = pressureEstimate?.pressureTokens !== undefined && Number.isFinite(pressureEstimate.pressureTokens) && typeof usableHard === "number" && usableHard > 0 ? pressureEstimate.pressureTokens / usableHard * 100 : 0;
|
|
25084
|
+
const grewPastSavedReading = savedProviderReading !== null && countPercentage >= 95 && countPercentage > savedProviderReading.percentage;
|
|
25085
|
+
if (savedProviderReading && !grewPastSavedReading) {
|
|
25086
|
+
contextUsage = {
|
|
25087
|
+
inputTokens: savedProviderReading.inputTokens,
|
|
25088
|
+
percentage: Math.max(contextUsage.percentage, savedProviderReading.percentage)
|
|
25089
|
+
};
|
|
25090
|
+
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)}`);
|
|
25091
|
+
} else if (pressureEstimate) {
|
|
25092
|
+
const percentageBeforeEstimate = contextUsage.percentage;
|
|
24901
25093
|
contextUsage = resolveUnknownUsageFromWireEstimate({
|
|
24902
25094
|
usage: contextUsage,
|
|
24903
25095
|
pricedPass: true,
|
|
24904
|
-
wireEstimateTokens: pressureEstimate.tokens,
|
|
25096
|
+
wireEstimateTokens: overflowRecoveryPass ? pressureEstimate.tokens : pressureEstimate.pressureTokens,
|
|
24905
25097
|
wireEstimateTrusted: pressureEstimate.trusted,
|
|
24906
25098
|
providerProvenInputTokens: providerProvenInputForRecovery,
|
|
24907
25099
|
providerProvenLimitTokens: providerProvenLimitForRecovery,
|
|
24908
|
-
usableHardLimit:
|
|
25100
|
+
usableHardLimit: usableHard
|
|
24909
25101
|
});
|
|
24910
25102
|
if (contextUsage.inputTokens > 0) {
|
|
24911
25103
|
const usedProviderInput = !pressureEstimate.trusted && providerProvenLimitForRecovery !== undefined && providerProvenInputForRecovery !== undefined && contextUsage.inputTokens >= providerProvenInputForRecovery;
|
|
24912
|
-
|
|
25104
|
+
contextUsageFromEstimate = !overflowRecoveryPass && !usedProviderInput && !usagePercentageSynthetic && contextUsage.percentage > percentageBeforeEstimate;
|
|
25105
|
+
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
25106
|
}
|
|
24914
|
-
} catch (error) {
|
|
24915
|
-
sessionLog2(sessionId, `transform: wire-estimate pressure fallback unavailable: ${getErrorMessage(error)}`);
|
|
24916
25107
|
}
|
|
24917
25108
|
}
|
|
24918
25109
|
const protectionUsableSoft = windowGeometry?.usableSoft ?? boundaryContextLimit;
|
|
@@ -24953,6 +25144,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24953
25144
|
activeAgent,
|
|
24954
25145
|
batch,
|
|
24955
25146
|
contextUsage,
|
|
25147
|
+
contextUsageFromEstimate,
|
|
24956
25148
|
usableWindow: resolvedContextLimit ?? 0,
|
|
24957
25149
|
schedulerDecision,
|
|
24958
25150
|
schedulerDeferReason,
|
|
@@ -24998,6 +25190,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
24998
25190
|
emergencyCeilingTokens,
|
|
24999
25191
|
pendingCompartmentInjection,
|
|
25000
25192
|
prefixTrimSourceOrder,
|
|
25193
|
+
coveredHostInstructions,
|
|
25001
25194
|
hiddenMessagesAtCompactionSeam,
|
|
25002
25195
|
trimmedMessagesAtCompactionBoundary,
|
|
25003
25196
|
didMutateFromFlushedStatuses,
|
|
@@ -25037,7 +25230,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25037
25230
|
postTransformResult.bustedThisPass = true;
|
|
25038
25231
|
passOutcome.markFinalized();
|
|
25039
25232
|
const finalWireTail = describeFinalWireTail(messages);
|
|
25040
|
-
const signedFitPreviouslyRefused = !compactionOff && getMergedReasoningStrippedIds(db, sessionId).has(SIGNED_FIT_REFUSED_MARKER);
|
|
25233
|
+
const signedFitPreviouslyRefused = !compactionOff && activeThinkingPrefixHold && getMergedReasoningStrippedIds(db, sessionId).has(SIGNED_FIT_REFUSED_MARKER);
|
|
25041
25234
|
let finalWireEstimate;
|
|
25042
25235
|
if (postTransformResult.bustedThisPass) {
|
|
25043
25236
|
try {
|
|
@@ -25198,7 +25391,12 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25198
25391
|
if (!finalWireEstimate) {
|
|
25199
25392
|
sessionLog2(sessionId, `transform: final-wire telemetry estimate=unavailable trusted=false conversation=unknown tools=unknown system=unknown toolDefinitions=unknown tail=${finalWireTail}`);
|
|
25200
25393
|
}
|
|
25201
|
-
|
|
25394
|
+
if (!compactionOff) {
|
|
25395
|
+
const stillUntagged = untaggedReplayTailServed && !recoveryNormalized ? [...untaggedReplayIds] : [];
|
|
25396
|
+
if (JSON.stringify([...new Set(stillUntagged)].sort()) !== JSON.stringify([...new Set(persistedUntaggedInputIds)].sort()) && !persistLkgUntaggedInputIds(db, sessionId, stillUntagged))
|
|
25397
|
+
throw new Error("Cannot persist the last-good untagged-message record");
|
|
25398
|
+
}
|
|
25399
|
+
finishSystemDateRefresh(deps.historyRefreshSessions, dateRequest, postTransformResult.bustedThisPass && !activeThinkingPrefixHold && postTransformResult.openTurnSignedThinkingKept !== true || postTransformResult.thinkingReleasedForFit === true, postTransformResult.openTurnSignedThinkingKept === true);
|
|
25202
25400
|
if (activeThinkingPrefixHold && !postTransformResult.thinkingReleasedForFit && sessionMeta.cachedM0Bytes != null && sessionMeta.cachedM1Bytes != null) {
|
|
25203
25401
|
recordHeldHeadForRequest(sessionId, currentLkgRequestIdentity(sessionId), (ownsHistory) => deferDeliveredSystemRefresh(deps, sessionId, ownsHistory));
|
|
25204
25402
|
}
|
|
@@ -25299,7 +25497,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
25299
25497
|
});
|
|
25300
25498
|
if (uncachedMessageIds.length > 0) {
|
|
25301
25499
|
try {
|
|
25302
|
-
storedByMessage = getActiveTagTokenTotalsByMessage2(db, sessionId, uncachedMessageIds);
|
|
25500
|
+
storedByMessage = omitIncompleteFileTokenTotals(db, sessionId, messages.flatMap((message) => message.info.id ? [{ id: message.info.id, parts: message.parts }] : []), getActiveTagTokenTotalsByMessage2(db, sessionId, uncachedMessageIds));
|
|
25303
25501
|
} catch {
|
|
25304
25502
|
storedByMessage = new Map;
|
|
25305
25503
|
}
|
|
@@ -25734,11 +25932,14 @@ function createSystemPromptHashHandler(deps) {
|
|
|
25734
25932
|
const stableCandidateHash = systemPromptFingerprint(stableCandidate, promptSurface.preset);
|
|
25735
25933
|
const contentOrPresetChanged = hasPersistedHash && stableCandidateHash !== previousHash;
|
|
25736
25934
|
const rewritePermission = systemDateRefreshPermission(deps.historyRefreshSessions, dateRequest);
|
|
25935
|
+
const signedThinkingKept = systemDateSignedThinkingKept(deps.historyRefreshSessions, dateRequest);
|
|
25936
|
+
const idleDateMayAdvance = idleCacheExpired && signedThinkingKept !== true;
|
|
25937
|
+
const prefixBoundModel = isPrefixBoundThinkingModel(liveModel?.providerID, liveModel?.modelID);
|
|
25737
25938
|
let deferredDateRefresh = false;
|
|
25738
|
-
if (currentDate && stickyDate && currentDate !== stickyDate &&
|
|
25939
|
+
if (currentDate && stickyDate && currentDate !== stickyDate && (idleCacheExpired ? prefixBoundModel : isCacheBusting) && !contentOrPresetChanged && !requestMessagesFinal) {
|
|
25739
25940
|
const liveElements = [...output.system];
|
|
25740
|
-
deferredDateRefresh = waitForSystemDateRefresh(deps.historyRefreshSessions, dateRequest, (permitted) => {
|
|
25741
|
-
if (!permitted) {
|
|
25941
|
+
deferredDateRefresh = waitForSystemDateRefresh(deps.historyRefreshSessions, dateRequest, (permitted, keptSignedThinking) => {
|
|
25942
|
+
if (!permitted && !(idleCacheExpired && keptSignedThinking !== true)) {
|
|
25742
25943
|
deps.systemPromptRefreshSessions.add(sessionId);
|
|
25743
25944
|
return;
|
|
25744
25945
|
}
|
|
@@ -25762,7 +25963,7 @@ function createSystemPromptHashHandler(deps) {
|
|
|
25762
25963
|
}
|
|
25763
25964
|
});
|
|
25764
25965
|
}
|
|
25765
|
-
const dateMayAdvance =
|
|
25966
|
+
const dateMayAdvance = idleDateMayAdvance && !deferredDateRefresh || contentOrPresetChanged || isCacheBusting && !deferredDateRefresh && (dateRequest ? rewritePermission === true : rewritePermission !== false);
|
|
25766
25967
|
if (currentDate && !stickyDate) {
|
|
25767
25968
|
stickyDateBySession.set(sessionId, currentDate);
|
|
25768
25969
|
} else if (currentDate && stickyDate && currentDate !== stickyDate) {
|
|
@@ -26166,7 +26367,8 @@ function tryMessagesTransformLkgReplay(args) {
|
|
|
26166
26367
|
sessionId,
|
|
26167
26368
|
entry,
|
|
26168
26369
|
messages: replay.messages,
|
|
26169
|
-
...keys
|
|
26370
|
+
...keys,
|
|
26371
|
+
db
|
|
26170
26372
|
}))
|
|
26171
26373
|
return false;
|
|
26172
26374
|
retirePendingSystemPromptDelivery(sessionId);
|
|
@@ -26798,6 +27000,7 @@ function renderItemByTag(db, sessionId, number, textIndexDomain = "part") {
|
|
|
26798
27000
|
}
|
|
26799
27001
|
|
|
26800
27002
|
// src/tools/ctx-expand/tools.ts
|
|
27003
|
+
var CTX_EXPAND_RUST_TAG_REFUSAL = "Tag lookup isn't available on this session: its §N§ tags are numbered by the Rust transform engine and ctx_expand cannot resolve those numbers, so no content was returned. Expand by message instead: ctx_expand(message=<ordinal>) or ctx_expand(start=<ordinal>, end=<ordinal>), using ordinals from a <session-history> heading or a ctx_search hit.";
|
|
26801
27004
|
var ctxExpandArgsShape = {
|
|
26802
27005
|
tag: tool.schema.union([tool.schema.number(), tool.schema.string()]).optional().describe("Tag number from a §N§ tag or a [dropped §N§] placeholder, not a message ordinal. Returns that one item in full. Use alone."),
|
|
26803
27006
|
start: tool.schema.number().optional().describe("First message ordinal of the range (a <session-history> heading's start, or a ctx_search hit), not a tag number."),
|
|
@@ -26820,9 +27023,12 @@ function createCtxExpandTool(deps) {
|
|
|
26820
27023
|
message: "number"
|
|
26821
27024
|
});
|
|
26822
27025
|
const sessionId = toolContext.sessionID;
|
|
27026
|
+
const mode = resolveCtxExpandMode(args, "positive");
|
|
27027
|
+
if (mode.kind === "tag" && deps.transformMode === "rust") {
|
|
27028
|
+
return CTX_EXPAND_RUST_TAG_REFUSAL;
|
|
27029
|
+
}
|
|
26823
27030
|
if (!await prepareRawSessionOrdinals2(sessionId))
|
|
26824
27031
|
return "Session ordinals are warming in the background. Retry ctx_expand shortly; no approximate ordinal was served.";
|
|
26825
|
-
const mode = resolveCtxExpandMode(args, "positive");
|
|
26826
27032
|
if (mode.kind === "error") {
|
|
26827
27033
|
return mode.message;
|
|
26828
27034
|
}
|