@cortexkit/opencode-magic-context 0.15.3 → 0.15.4
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/README.md +2 -2
- package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +13 -0
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts +71 -2
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +3 -0
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/live-session-state.d.ts +19 -0
- package/dist/hooks/magic-context/live-session-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +17 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/tokenizer-calibration.d.ts +85 -0
- package/dist/hooks/magic-context/tokenizer-calibration.d.ts.map +1 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +4 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +8 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +17 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/index.js +313 -40
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/plugin/sidebar-snapshot-cache.d.ts +19 -0
- package/dist/plugin/sidebar-snapshot-cache.d.ts.map +1 -0
- package/dist/shared/rpc-types.d.ts +0 -9
- package/dist/shared/rpc-types.d.ts.map +1 -1
- package/dist/tui/data/context-db.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/shared/rpc-types.ts +0 -9
- package/src/tui/data/context-db.ts +66 -4
- package/src/tui/index.tsx +0 -3
- package/src/tui/slots/sidebar-content.tsx +0 -15
- package/dist/plugin/tui-action-consumer.d.ts +0 -15
- package/dist/plugin/tui-action-consumer.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -149473,7 +149473,21 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
149473
149473
|
this.recordFailure(isProbe);
|
|
149474
149474
|
return Array.from({ length: texts.length }, () => null);
|
|
149475
149475
|
}
|
|
149476
|
-
const
|
|
149476
|
+
const rawBody = await response.text();
|
|
149477
|
+
if (rawBody.trim().length === 0) {
|
|
149478
|
+
log(`[magic-context] openai-compatible embedding request returned empty body (status=${response.status}, content-type=${response.headers.get("content-type") ?? "none"})`);
|
|
149479
|
+
this.recordFailure(isProbe);
|
|
149480
|
+
return Array.from({ length: texts.length }, () => null);
|
|
149481
|
+
}
|
|
149482
|
+
let body;
|
|
149483
|
+
try {
|
|
149484
|
+
body = JSON.parse(rawBody);
|
|
149485
|
+
} catch (parseError) {
|
|
149486
|
+
const snippet = rawBody.slice(0, 200).replace(/\s+/g, " ");
|
|
149487
|
+
log(`[magic-context] openai-compatible embedding response was not JSON (status=${response.status}, ${rawBody.length}B body, snippet="${snippet}"):`, parseError instanceof Error ? parseError.message : parseError);
|
|
149488
|
+
this.recordFailure(isProbe);
|
|
149489
|
+
return Array.from({ length: texts.length }, () => null);
|
|
149490
|
+
}
|
|
149477
149491
|
const items = Array.isArray(body.data) ? body.data : [];
|
|
149478
149492
|
const results = Array.from({ length: texts.length }, (_, index) => {
|
|
149479
149493
|
const embedding = items[index]?.embedding;
|
|
@@ -154598,7 +154612,7 @@ No new compartments or facts were written. Check the historian model/output and
|
|
|
154598
154612
|
})();
|
|
154599
154613
|
clearInjectionCache(sessionId);
|
|
154600
154614
|
deps.onInjectionCacheCleared?.(sessionId);
|
|
154601
|
-
if (deps.directory) {
|
|
154615
|
+
if (deps.directory && deps.memoryEnabled !== false && deps.autoPromote !== false) {
|
|
154602
154616
|
promoteSessionFactsToMemory(db, sessionId, resolveProjectIdentity(deps.directory), validatedPass.facts ?? []);
|
|
154603
154617
|
}
|
|
154604
154618
|
const lastCompartmentEnd = lastNewEnd;
|
|
@@ -154704,7 +154718,7 @@ async function executeContextRecompInternal(deps) {
|
|
|
154704
154718
|
clearCompressionDepth(db, sessionId);
|
|
154705
154719
|
clearInjectionCache(sessionId);
|
|
154706
154720
|
deps.onInjectionCacheCleared?.(sessionId);
|
|
154707
|
-
if (deps.directory) {
|
|
154721
|
+
if (deps.directory && deps.memoryEnabled !== false && deps.autoPromote !== false) {
|
|
154708
154722
|
promoteSessionFactsToMemory(db, sessionId, resolveProjectIdentity(deps.directory), promoted2.facts);
|
|
154709
154723
|
}
|
|
154710
154724
|
const lastCompartmentEnd2 = promoted2.compartments[promoted2.compartments.length - 1]?.endMessage ?? 0;
|
|
@@ -154875,7 +154889,7 @@ Nothing was written.`;
|
|
|
154875
154889
|
deps.onInjectionCacheCleared?.(sessionId);
|
|
154876
154890
|
const finalCompartments = promoted?.compartments ?? candidateCompartments;
|
|
154877
154891
|
const finalFacts = promoted?.facts ?? candidateFacts;
|
|
154878
|
-
if (deps.directory) {
|
|
154892
|
+
if (deps.directory && deps.memoryEnabled !== false && deps.autoPromote !== false) {
|
|
154879
154893
|
promoteSessionFactsToMemory(db, sessionId, resolveProjectIdentity(deps.directory), finalFacts);
|
|
154880
154894
|
}
|
|
154881
154895
|
const lastCompartmentEnd = finalCompartments[finalCompartments.length - 1]?.endMessage ?? 0;
|
|
@@ -163607,7 +163621,10 @@ function createLiveSessionState() {
|
|
|
163607
163621
|
return {
|
|
163608
163622
|
liveModelBySession: new Map,
|
|
163609
163623
|
variantBySession: new Map,
|
|
163610
|
-
agentBySession: new Map
|
|
163624
|
+
agentBySession: new Map,
|
|
163625
|
+
historyRefreshSessions: new Set,
|
|
163626
|
+
systemPromptRefreshSessions: new Set,
|
|
163627
|
+
pendingMaterializationSessions: new Set
|
|
163611
163628
|
};
|
|
163612
163629
|
}
|
|
163613
163630
|
|
|
@@ -167484,6 +167501,8 @@ async function runCompartmentPhase(args) {
|
|
|
167484
167501
|
historianTwoPass: args.historianTwoPass,
|
|
167485
167502
|
compressorMinCompartmentRatio: args.compressorMinCompartmentRatio,
|
|
167486
167503
|
compressorMaxMergeDepth: args.compressorMaxMergeDepth,
|
|
167504
|
+
memoryEnabled: args.memoryEnabled,
|
|
167505
|
+
autoPromote: args.autoPromote,
|
|
167487
167506
|
onInjectionCacheCleared: args.onInjectionCacheCleared
|
|
167488
167507
|
});
|
|
167489
167508
|
compartmentInProgress = true;
|
|
@@ -167509,6 +167528,8 @@ async function runCompartmentPhase(args) {
|
|
|
167509
167528
|
historianTwoPass: args.historianTwoPass,
|
|
167510
167529
|
compressorMinCompartmentRatio: args.compressorMinCompartmentRatio,
|
|
167511
167530
|
compressorMaxMergeDepth: args.compressorMaxMergeDepth,
|
|
167531
|
+
memoryEnabled: args.memoryEnabled,
|
|
167532
|
+
autoPromote: args.autoPromote,
|
|
167512
167533
|
onInjectionCacheCleared: args.onInjectionCacheCleared
|
|
167513
167534
|
});
|
|
167514
167535
|
activeRun = getActiveCompartmentRun(args.sessionId);
|
|
@@ -169273,7 +169294,7 @@ function logTransformTiming(sessionId, stage, startMs, extra) {
|
|
|
169273
169294
|
// src/hooks/magic-context/transform-postprocess-phase.ts
|
|
169274
169295
|
async function runPostTransformPhase(args) {
|
|
169275
169296
|
let didMutateFromPendingOperations = false;
|
|
169276
|
-
const isExplicitFlush = args.
|
|
169297
|
+
const isExplicitFlush = args.pendingMaterializationSessions.has(args.sessionId);
|
|
169277
169298
|
const alreadyRanThisTurn = args.currentTurnId !== null && args.lastHeuristicsTurnId.get(args.sessionId) === args.currentTurnId;
|
|
169278
169299
|
const forceMaterialization = args.fullFeatureMode && args.contextUsage.percentage >= args.forceMaterializationPercentage;
|
|
169279
169300
|
const activeCompartmentRun = args.canRunCompartments ? getActiveCompartmentRun(args.sessionId) : undefined;
|
|
@@ -169283,8 +169304,8 @@ async function runPostTransformPhase(args) {
|
|
|
169283
169304
|
const pendingOps = shouldReadPendingOps ? getPendingOps(args.db, args.sessionId) : [];
|
|
169284
169305
|
const hasPendingUserOps = pendingOps.length > 0;
|
|
169285
169306
|
const shouldApplyPendingOps = (args.schedulerDecision === "execute" || isExplicitFlush || forceMaterialization) && (!compartmentRunning || emergencyBypassCompartmentGate);
|
|
169286
|
-
const isCacheBustingPass = isExplicitFlush || shouldApplyPendingOps;
|
|
169287
169307
|
const shouldRunHeuristics = (!compartmentRunning || emergencyBypassCompartmentGate) && (isExplicitFlush || forceMaterialization || args.schedulerDecision === "execute" && !alreadyRanThisTurn);
|
|
169308
|
+
const isCacheBustingPass = shouldApplyPendingOps || shouldRunHeuristics;
|
|
169288
169309
|
if (shouldRunHeuristics) {
|
|
169289
169310
|
const reason = isExplicitFlush ? "explicit_flush" : forceMaterialization ? `force_materialization (${args.contextUsage.percentage.toFixed(1)}% >= ${args.forceMaterializationPercentage}%)` : `scheduler_execute (pendingOps=${pendingOps.length}, scheduler=${args.schedulerDecision})`;
|
|
169290
169311
|
sessionLog(args.sessionId, `heuristics WILL RUN \u2014 reason=${reason}, context=${args.contextUsage.percentage.toFixed(1)}%, turn=${args.currentTurnId}`);
|
|
@@ -169358,7 +169379,7 @@ async function runPostTransformPhase(args) {
|
|
|
169358
169379
|
}
|
|
169359
169380
|
}
|
|
169360
169381
|
logTransformTiming(args.sessionId, "clearOldReasoning", t7);
|
|
169361
|
-
args.
|
|
169382
|
+
args.pendingMaterializationSessions.delete(args.sessionId);
|
|
169362
169383
|
if (args.currentTurnId) {
|
|
169363
169384
|
args.lastHeuristicsTurnId.set(args.sessionId, args.currentTurnId);
|
|
169364
169385
|
}
|
|
@@ -169687,7 +169708,7 @@ function createTransform(deps) {
|
|
|
169687
169708
|
}
|
|
169688
169709
|
const historyBudgetTokens = resolveHistoryBudgetTokens(deps.historyBudgetPercentage, contextUsageEarly, deps.executeThresholdPercentage, deps.getModelKey?.(sessionId), deps.executeThresholdTokens);
|
|
169689
169710
|
const schedulerDecisionEarly = resolveSchedulerDecision(deps.scheduler, sessionMeta, contextUsageEarly, sessionId, deps.getModelKey?.(sessionId));
|
|
169690
|
-
const isCacheBusting = deps.
|
|
169711
|
+
const isCacheBusting = deps.historyRefreshSessions.has(sessionId);
|
|
169691
169712
|
if (historianFailureState.failureCount === 0) {
|
|
169692
169713
|
lastEmergencyNotificationCount.delete(sessionId);
|
|
169693
169714
|
}
|
|
@@ -169724,8 +169745,11 @@ function createTransform(deps) {
|
|
|
169724
169745
|
historianTwoPass: deps.historianTwoPass,
|
|
169725
169746
|
compressorMinCompartmentRatio: deps.compressorMinCompartmentRatio,
|
|
169726
169747
|
compressorMaxMergeDepth: deps.compressorMaxMergeDepth,
|
|
169748
|
+
memoryEnabled: deps.memoryConfig?.enabled,
|
|
169749
|
+
autoPromote: deps.memoryConfig?.autoPromote,
|
|
169727
169750
|
onInjectionCacheCleared: (sid) => {
|
|
169728
|
-
deps.
|
|
169751
|
+
deps.historyRefreshSessions.add(sid);
|
|
169752
|
+
deps.pendingMaterializationSessions.add(sid);
|
|
169729
169753
|
}
|
|
169730
169754
|
});
|
|
169731
169755
|
skipCompartmentAwaitForThisPass = true;
|
|
@@ -169762,6 +169786,9 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so ma
|
|
|
169762
169786
|
const tInj = performance.now();
|
|
169763
169787
|
pendingCompartmentInjection = prepareCompartmentInjection(db, sessionId, messages, isCacheBusting, projectIdentity, deps.memoryConfig?.injectionBudgetTokens, deps.experimentalTemporalAwareness);
|
|
169764
169788
|
logTransformTiming(sessionId, "prepareCompartmentInjection", tInj);
|
|
169789
|
+
if (isCacheBusting) {
|
|
169790
|
+
deps.historyRefreshSessions.delete(sessionId);
|
|
169791
|
+
}
|
|
169765
169792
|
}
|
|
169766
169793
|
let targets = new Map;
|
|
169767
169794
|
let reasoningByMessage = new Map;
|
|
@@ -169887,8 +169914,11 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so ma
|
|
|
169887
169914
|
compressorMinCompartmentRatio: deps.compressorMinCompartmentRatio,
|
|
169888
169915
|
compressorMaxMergeDepth: deps.compressorMaxMergeDepth,
|
|
169889
169916
|
compressorCooldownMs: deps.compressorCooldownMs,
|
|
169917
|
+
memoryEnabled: deps.memoryConfig?.enabled,
|
|
169918
|
+
autoPromote: deps.memoryConfig?.autoPromote,
|
|
169890
169919
|
onInjectionCacheCleared: (sid) => {
|
|
169891
|
-
deps.
|
|
169920
|
+
deps.historyRefreshSessions.add(sid);
|
|
169921
|
+
deps.pendingMaterializationSessions.add(sid);
|
|
169892
169922
|
}
|
|
169893
169923
|
});
|
|
169894
169924
|
pendingCompartmentInjection = compartmentPhase.pendingCompartmentInjection;
|
|
@@ -169914,7 +169944,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so ma
|
|
|
169914
169944
|
compartmentInProgress,
|
|
169915
169945
|
sessionMeta,
|
|
169916
169946
|
currentTurnId,
|
|
169917
|
-
|
|
169947
|
+
pendingMaterializationSessions: deps.pendingMaterializationSessions,
|
|
169918
169948
|
lastHeuristicsTurnId: deps.lastHeuristicsTurnId,
|
|
169919
169949
|
autoDropToolAge: deps.autoDropToolAge,
|
|
169920
169950
|
dropToolStructure: deps.dropToolStructure ?? true,
|
|
@@ -170535,6 +170565,43 @@ init_compartment_runner();
|
|
|
170535
170565
|
init_storage();
|
|
170536
170566
|
init_storage_meta();
|
|
170537
170567
|
init_storage_meta_persisted();
|
|
170568
|
+
|
|
170569
|
+
// src/plugin/sidebar-snapshot-cache.ts
|
|
170570
|
+
var MAX_CACHED_SESSIONS = 100;
|
|
170571
|
+
var STALE_SNAPSHOT_AGE_MS = 5 * 60 * 1000;
|
|
170572
|
+
var cache = new BoundedSessionMap(MAX_CACHED_SESSIONS);
|
|
170573
|
+
function applyStickySnapshotCache(sessionId, fresh) {
|
|
170574
|
+
const now = Date.now();
|
|
170575
|
+
if (fresh.inputTokens > 0) {
|
|
170576
|
+
cache.set(sessionId, { snapshot: fresh, cachedAt: now });
|
|
170577
|
+
return fresh;
|
|
170578
|
+
}
|
|
170579
|
+
const cached2 = cache.peek(sessionId);
|
|
170580
|
+
if (!cached2) {
|
|
170581
|
+
return fresh;
|
|
170582
|
+
}
|
|
170583
|
+
if (now - cached2.cachedAt > STALE_SNAPSHOT_AGE_MS) {
|
|
170584
|
+
cache.delete(sessionId);
|
|
170585
|
+
return fresh;
|
|
170586
|
+
}
|
|
170587
|
+
return {
|
|
170588
|
+
...fresh,
|
|
170589
|
+
usagePercentage: cached2.snapshot.usagePercentage,
|
|
170590
|
+
inputTokens: cached2.snapshot.inputTokens,
|
|
170591
|
+
systemPromptTokens: cached2.snapshot.systemPromptTokens,
|
|
170592
|
+
compartmentTokens: cached2.snapshot.compartmentTokens,
|
|
170593
|
+
factTokens: cached2.snapshot.factTokens,
|
|
170594
|
+
memoryTokens: cached2.snapshot.memoryTokens,
|
|
170595
|
+
conversationTokens: cached2.snapshot.conversationTokens,
|
|
170596
|
+
toolCallTokens: cached2.snapshot.toolCallTokens,
|
|
170597
|
+
toolDefinitionTokens: cached2.snapshot.toolDefinitionTokens
|
|
170598
|
+
};
|
|
170599
|
+
}
|
|
170600
|
+
function clearSidebarSnapshotCache(sessionId) {
|
|
170601
|
+
cache.delete(sessionId);
|
|
170602
|
+
}
|
|
170603
|
+
|
|
170604
|
+
// src/hooks/magic-context/hook-handlers.ts
|
|
170538
170605
|
init_logger();
|
|
170539
170606
|
init_note_nudger();
|
|
170540
170607
|
var TOOL_HEAVY_TURN_REMINDER_THRESHOLD = 5;
|
|
@@ -170578,7 +170645,9 @@ function createChatMessageHook(args) {
|
|
|
170578
170645
|
}
|
|
170579
170646
|
if (previousVariant !== undefined && input.variant !== undefined && previousVariant !== input.variant) {
|
|
170580
170647
|
sessionLog(sessionId, `variant changed (${previousVariant} -> ${input.variant}), triggering flush`);
|
|
170581
|
-
args.
|
|
170648
|
+
args.historyRefreshSessions.add(sessionId);
|
|
170649
|
+
args.systemPromptRefreshSessions.add(sessionId);
|
|
170650
|
+
args.pendingMaterializationSessions.add(sessionId);
|
|
170582
170651
|
args.lastHeuristicsTurnId.delete(sessionId);
|
|
170583
170652
|
}
|
|
170584
170653
|
};
|
|
@@ -170614,11 +170683,14 @@ function createEventHook(args) {
|
|
|
170614
170683
|
args.agentBySession.delete(sessionId);
|
|
170615
170684
|
args.recentReduceBySession.delete(sessionId);
|
|
170616
170685
|
args.toolUsageSinceUserTurn.delete(sessionId);
|
|
170617
|
-
args.
|
|
170686
|
+
args.historyRefreshSessions.delete(sessionId);
|
|
170687
|
+
args.systemPromptRefreshSessions.delete(sessionId);
|
|
170688
|
+
args.pendingMaterializationSessions.delete(sessionId);
|
|
170618
170689
|
args.lastHeuristicsTurnId.delete(sessionId);
|
|
170619
170690
|
args.commitSeenLastPass?.delete(sessionId);
|
|
170620
170691
|
clearNoteNudgeState(args.db, sessionId);
|
|
170621
170692
|
clearAutoSearchForSession(sessionId);
|
|
170693
|
+
clearSidebarSnapshotCache(sessionId);
|
|
170622
170694
|
}
|
|
170623
170695
|
};
|
|
170624
170696
|
}
|
|
@@ -170940,7 +171012,7 @@ function createSystemPromptHashHandler(deps) {
|
|
|
170940
171012
|
output.system.push(guidance);
|
|
170941
171013
|
sessionLog(sessionId, `injected ${detectedAgent ?? "generic"} guidance into system prompt (ctxReduce=${effectiveCtxReduceEnabled}, subagent=${isSubagentSession})`);
|
|
170942
171014
|
}
|
|
170943
|
-
const isCacheBusting = deps.
|
|
171015
|
+
const isCacheBusting = deps.systemPromptRefreshSessions.has(sessionId);
|
|
170944
171016
|
if (shouldInjectDocs && !isSubagentSession) {
|
|
170945
171017
|
const hasCached = cachedDocsBySession.has(sessionId);
|
|
170946
171018
|
if (!hasCached || isCacheBusting) {
|
|
@@ -171077,7 +171149,9 @@ ${sections.join(`
|
|
|
171077
171149
|
const previousHash = sessionMeta.systemPromptHash;
|
|
171078
171150
|
if (previousHash !== "" && previousHash !== "0" && previousHash !== currentHash) {
|
|
171079
171151
|
sessionLog(sessionId, `system prompt hash changed: ${previousHash} \u2192 ${currentHash} (len=${systemContent.length}), triggering flush`);
|
|
171080
|
-
deps.
|
|
171152
|
+
deps.historyRefreshSessions.add(sessionId);
|
|
171153
|
+
deps.systemPromptRefreshSessions.add(sessionId);
|
|
171154
|
+
deps.pendingMaterializationSessions.add(sessionId);
|
|
171081
171155
|
deps.lastHeuristicsTurnId.delete(sessionId);
|
|
171082
171156
|
} else if (previousHash === "" || previousHash === "0") {
|
|
171083
171157
|
sessionLog(sessionId, `system prompt hash initialized: ${currentHash} (len=${systemContent.length})`);
|
|
@@ -171091,6 +171165,9 @@ ${sections.join(`
|
|
|
171091
171165
|
} else if (Math.abs(sessionMeta.systemPromptTokens - systemPromptTokens) > 50) {
|
|
171092
171166
|
updateSessionMeta(deps.db, sessionId, { systemPromptTokens });
|
|
171093
171167
|
}
|
|
171168
|
+
if (isCacheBusting) {
|
|
171169
|
+
deps.systemPromptRefreshSessions.delete(sessionId);
|
|
171170
|
+
}
|
|
171094
171171
|
};
|
|
171095
171172
|
return {
|
|
171096
171173
|
handler,
|
|
@@ -171149,7 +171226,9 @@ function createMagicContextHook(deps) {
|
|
|
171149
171226
|
let lastScheduleCheckMs = 0;
|
|
171150
171227
|
const getHistorianChunkTokens = () => deriveHistorianChunkTokens(resolveHistorianContextLimit(deps.config.historian?.model));
|
|
171151
171228
|
const nudgePlacements = createNudgePlacementStore(db);
|
|
171152
|
-
const
|
|
171229
|
+
const historyRefreshSessions = deps.liveSessionState?.historyRefreshSessions ?? new Set;
|
|
171230
|
+
const systemPromptRefreshSessions = deps.liveSessionState?.systemPromptRefreshSessions ?? new Set;
|
|
171231
|
+
const pendingMaterializationSessions = deps.liveSessionState?.pendingMaterializationSessions ?? new Set;
|
|
171153
171232
|
const lastHeuristicsTurnId = new Map;
|
|
171154
171233
|
const commitSeenLastPass = new Map;
|
|
171155
171234
|
const variantBySession = deps.liveSessionState?.variantBySession ?? new Map;
|
|
@@ -171188,14 +171267,16 @@ function createMagicContextHook(deps) {
|
|
|
171188
171267
|
autoDropToolAge: deps.config.auto_drop_tool_age ?? 100,
|
|
171189
171268
|
dropToolStructure: deps.config.drop_tool_structure ?? true,
|
|
171190
171269
|
clearReasoningAge: deps.config.clear_reasoning_age ?? 50,
|
|
171191
|
-
|
|
171270
|
+
historyRefreshSessions,
|
|
171271
|
+
pendingMaterializationSessions,
|
|
171192
171272
|
lastHeuristicsTurnId,
|
|
171193
171273
|
commitSeenLastPass,
|
|
171194
171274
|
client: deps.client,
|
|
171195
171275
|
directory: deps.directory,
|
|
171196
171276
|
memoryConfig: deps.config.memory ? {
|
|
171197
171277
|
enabled: deps.config.memory.enabled,
|
|
171198
|
-
injectionBudgetTokens: deps.config.memory.injection_budget_tokens
|
|
171278
|
+
injectionBudgetTokens: deps.config.memory.injection_budget_tokens,
|
|
171279
|
+
autoPromote: deps.config.memory.auto_promote ?? true
|
|
171199
171280
|
} : undefined,
|
|
171200
171281
|
getHistorianChunkTokens,
|
|
171201
171282
|
historyBudgetPercentage: deps.config.history_budget_percentage,
|
|
@@ -171301,7 +171382,11 @@ function createMagicContextHook(deps) {
|
|
|
171301
171382
|
return;
|
|
171302
171383
|
return resolveContextLimit(model.providerID, model.modelID);
|
|
171303
171384
|
},
|
|
171304
|
-
onFlush: (sessionId) =>
|
|
171385
|
+
onFlush: (sessionId) => {
|
|
171386
|
+
historyRefreshSessions.add(sessionId);
|
|
171387
|
+
systemPromptRefreshSessions.add(sessionId);
|
|
171388
|
+
pendingMaterializationSessions.add(sessionId);
|
|
171389
|
+
},
|
|
171305
171390
|
executeRecomp: async (sessionId, options) => executeContextRecomp({
|
|
171306
171391
|
client: deps.client,
|
|
171307
171392
|
db,
|
|
@@ -171315,8 +171400,11 @@ function createMagicContextHook(deps) {
|
|
|
171315
171400
|
})(),
|
|
171316
171401
|
getNotificationParams: () => getLiveNotificationParams(sessionId, liveModelBySession, variantBySession, agentBySession),
|
|
171317
171402
|
historianTwoPass: deps.config.historian?.two_pass === true,
|
|
171403
|
+
memoryEnabled: deps.config.memory?.enabled,
|
|
171404
|
+
autoPromote: deps.config.memory?.auto_promote ?? true,
|
|
171318
171405
|
onInjectionCacheCleared: (sid) => {
|
|
171319
|
-
|
|
171406
|
+
historyRefreshSessions.add(sid);
|
|
171407
|
+
pendingMaterializationSessions.add(sid);
|
|
171320
171408
|
}
|
|
171321
171409
|
}, options),
|
|
171322
171410
|
sendNotification: async (sessionId, text, params) => {
|
|
@@ -171355,7 +171443,9 @@ function createMagicContextHook(deps) {
|
|
|
171355
171443
|
dreamerEnabled: deps.config.dreamer?.enabled === true,
|
|
171356
171444
|
injectDocs: deps.config.dreamer?.inject_docs !== false,
|
|
171357
171445
|
directory: deps.directory,
|
|
171358
|
-
|
|
171446
|
+
historyRefreshSessions,
|
|
171447
|
+
systemPromptRefreshSessions,
|
|
171448
|
+
pendingMaterializationSessions,
|
|
171359
171449
|
lastHeuristicsTurnId,
|
|
171360
171450
|
experimentalUserMemories: deps.config.dreamer?.user_memories?.enabled,
|
|
171361
171451
|
experimentalPinKeyFiles: deps.config.dreamer?.pin_key_files?.enabled ?? false,
|
|
@@ -171372,7 +171462,9 @@ function createMagicContextHook(deps) {
|
|
|
171372
171462
|
agentBySession,
|
|
171373
171463
|
recentReduceBySession,
|
|
171374
171464
|
toolUsageSinceUserTurn,
|
|
171375
|
-
|
|
171465
|
+
historyRefreshSessions,
|
|
171466
|
+
systemPromptRefreshSessions,
|
|
171467
|
+
pendingMaterializationSessions,
|
|
171376
171468
|
lastHeuristicsTurnId,
|
|
171377
171469
|
commitSeenLastPass,
|
|
171378
171470
|
client: deps.client,
|
|
@@ -171390,7 +171482,9 @@ function createMagicContextHook(deps) {
|
|
|
171390
171482
|
liveModelBySession,
|
|
171391
171483
|
variantBySession,
|
|
171392
171484
|
agentBySession,
|
|
171393
|
-
|
|
171485
|
+
historyRefreshSessions,
|
|
171486
|
+
systemPromptRefreshSessions,
|
|
171487
|
+
pendingMaterializationSessions,
|
|
171394
171488
|
lastHeuristicsTurnId,
|
|
171395
171489
|
ctxReduceEnabled
|
|
171396
171490
|
}),
|
|
@@ -171508,6 +171602,166 @@ function truncateError(name2, code, message, maxLen = 240) {
|
|
|
171508
171602
|
init_project_identity();
|
|
171509
171603
|
init_storage();
|
|
171510
171604
|
init_read_session_formatting();
|
|
171605
|
+
|
|
171606
|
+
// src/hooks/magic-context/tokenizer-calibration.ts
|
|
171607
|
+
var CALIBRATION_TABLE = [
|
|
171608
|
+
{ prefix: "anthropic/claude-opus-4-7", systemRatio: 1.51, toolsRatio: 1.57 },
|
|
171609
|
+
{ prefix: "anthropic/claude-opus-4.7", systemRatio: 1.51, toolsRatio: 1.57 },
|
|
171610
|
+
{ prefix: "anthropic/claude-opus-4-5", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171611
|
+
{ prefix: "anthropic/claude-opus-4.5", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171612
|
+
{ prefix: "anthropic/claude-opus-4-6", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171613
|
+
{ prefix: "anthropic/claude-opus-4.6", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171614
|
+
{ prefix: "anthropic/claude-sonnet-4-5", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171615
|
+
{ prefix: "anthropic/claude-sonnet-4.5", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171616
|
+
{ prefix: "anthropic/claude-sonnet-4-6", systemRatio: 1.02, toolsRatio: 1.14 },
|
|
171617
|
+
{ prefix: "anthropic/claude-sonnet-4.6", systemRatio: 1.02, toolsRatio: 1.14 },
|
|
171618
|
+
{ prefix: "anthropic/claude-haiku-4-5", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171619
|
+
{ prefix: "anthropic/claude-haiku-4.5", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171620
|
+
{ prefix: "openrouter/anthropic/claude-opus-4-7", systemRatio: 1.51, toolsRatio: 1.57 },
|
|
171621
|
+
{ prefix: "openrouter/anthropic/claude-opus-4.7", systemRatio: 1.51, toolsRatio: 1.57 },
|
|
171622
|
+
{ prefix: "github-copilot/claude-opus-4-7", systemRatio: 1.51, toolsRatio: 1.57 },
|
|
171623
|
+
{ prefix: "github-copilot/claude-opus-4.7", systemRatio: 1.51, toolsRatio: 1.57 },
|
|
171624
|
+
{ prefix: "openrouter/anthropic/claude-sonnet-4.6", systemRatio: 1.02, toolsRatio: 1.14 },
|
|
171625
|
+
{ prefix: "github-copilot/claude-sonnet-4.6", systemRatio: 1.02, toolsRatio: 1.14 },
|
|
171626
|
+
{ prefix: "github-copilot/claude-sonnet-4.5", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171627
|
+
{ prefix: "github-copilot/claude-opus-4.5", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171628
|
+
{ prefix: "github-copilot/claude-haiku-4.5", systemRatio: 1.02, toolsRatio: 1.16 },
|
|
171629
|
+
{ prefix: "openai/gpt-5", systemRatio: 1, toolsRatio: 0.84 },
|
|
171630
|
+
{ prefix: "xai/grok-4", systemRatio: 0.82, toolsRatio: 0.88 },
|
|
171631
|
+
{ prefix: "xai/grok-code-fast", systemRatio: 0.82, toolsRatio: 0.89 },
|
|
171632
|
+
{ prefix: "cerebras/qwen-3-235b", systemRatio: 1, toolsRatio: 1.1 },
|
|
171633
|
+
{ prefix: "cerebras/zai-glm-4.7", systemRatio: 1, toolsRatio: 1.09 },
|
|
171634
|
+
{ prefix: "cerebras/gpt-oss-120b", systemRatio: 0.84, toolsRatio: 0.79 },
|
|
171635
|
+
{
|
|
171636
|
+
prefix: "fireworks-ai/accounts/fireworks/models/glm-5p1",
|
|
171637
|
+
systemRatio: 1,
|
|
171638
|
+
toolsRatio: 1.06
|
|
171639
|
+
},
|
|
171640
|
+
{
|
|
171641
|
+
prefix: "fireworks-ai/accounts/fireworks/models/deepseek-v3p2",
|
|
171642
|
+
systemRatio: 1.05,
|
|
171643
|
+
toolsRatio: 1.09
|
|
171644
|
+
},
|
|
171645
|
+
{ prefix: "opencode-go/glm-5.1", systemRatio: 1, toolsRatio: 1.06 },
|
|
171646
|
+
{ prefix: "opencode-go/glm-5", systemRatio: 1, toolsRatio: 1.06 },
|
|
171647
|
+
{ prefix: "opencode-go/kimi-k2.6", systemRatio: 0.87, toolsRatio: 0.86 }
|
|
171648
|
+
];
|
|
171649
|
+
var NEUTRAL = { systemRatio: 1, toolsRatio: 1 };
|
|
171650
|
+
function resolveModelCalibration(providerId, modelId) {
|
|
171651
|
+
if (!providerId || !modelId)
|
|
171652
|
+
return NEUTRAL;
|
|
171653
|
+
const key = `${providerId}/${modelId}`.toLowerCase();
|
|
171654
|
+
let best = null;
|
|
171655
|
+
for (const entry of CALIBRATION_TABLE) {
|
|
171656
|
+
const prefix = entry.prefix.toLowerCase();
|
|
171657
|
+
if (!key.startsWith(prefix))
|
|
171658
|
+
continue;
|
|
171659
|
+
if (!best || prefix.length > best.prefix.length) {
|
|
171660
|
+
best = entry;
|
|
171661
|
+
}
|
|
171662
|
+
}
|
|
171663
|
+
return best ?? NEUTRAL;
|
|
171664
|
+
}
|
|
171665
|
+
function calibrateBuckets(input) {
|
|
171666
|
+
const empty = {
|
|
171667
|
+
systemTokens: 0,
|
|
171668
|
+
toolDefinitionTokens: 0,
|
|
171669
|
+
compartmentTokens: 0,
|
|
171670
|
+
factTokens: 0,
|
|
171671
|
+
memoryTokens: 0,
|
|
171672
|
+
conversationTokens: 0,
|
|
171673
|
+
toolCallTokens: 0
|
|
171674
|
+
};
|
|
171675
|
+
if (input.inputTokens <= 0)
|
|
171676
|
+
return empty;
|
|
171677
|
+
let calibratedSystem = Math.round(input.systemLocal * input.calibration.systemRatio);
|
|
171678
|
+
let calibratedToolDefs = Math.round(input.toolDefsLocal * input.calibration.toolsRatio);
|
|
171679
|
+
let compartments = Math.max(0, input.compartmentsLocal);
|
|
171680
|
+
let facts = Math.max(0, input.factsLocal);
|
|
171681
|
+
let memories = Math.max(0, input.memoriesLocal);
|
|
171682
|
+
const nonResidualTotal = calibratedSystem + calibratedToolDefs + compartments + facts + memories;
|
|
171683
|
+
if (nonResidualTotal > input.inputTokens) {
|
|
171684
|
+
const ratio = input.inputTokens / nonResidualTotal;
|
|
171685
|
+
calibratedSystem = Math.round(calibratedSystem * ratio);
|
|
171686
|
+
calibratedToolDefs = Math.round(calibratedToolDefs * ratio);
|
|
171687
|
+
compartments = Math.round(compartments * ratio);
|
|
171688
|
+
facts = Math.round(facts * ratio);
|
|
171689
|
+
memories = Math.round(memories * ratio);
|
|
171690
|
+
}
|
|
171691
|
+
const residualTarget = Math.max(0, input.inputTokens - calibratedSystem - calibratedToolDefs - compartments - facts - memories);
|
|
171692
|
+
const residualLocalSum = input.conversationLocal + input.toolCallsLocal;
|
|
171693
|
+
let conversation;
|
|
171694
|
+
let toolCalls;
|
|
171695
|
+
if (residualLocalSum <= 0) {
|
|
171696
|
+
conversation = residualTarget;
|
|
171697
|
+
toolCalls = 0;
|
|
171698
|
+
} else {
|
|
171699
|
+
const scale = residualTarget / residualLocalSum;
|
|
171700
|
+
conversation = Math.round(input.conversationLocal * scale);
|
|
171701
|
+
toolCalls = Math.round(input.toolCallsLocal * scale);
|
|
171702
|
+
}
|
|
171703
|
+
const provisionalSum = calibratedSystem + calibratedToolDefs + compartments + facts + memories + conversation + toolCalls;
|
|
171704
|
+
let delta = input.inputTokens - provisionalSum;
|
|
171705
|
+
if (delta !== 0) {
|
|
171706
|
+
if (conversation >= toolCalls) {
|
|
171707
|
+
const adjusted = Math.max(0, conversation + delta);
|
|
171708
|
+
delta -= adjusted - conversation;
|
|
171709
|
+
conversation = adjusted;
|
|
171710
|
+
} else {
|
|
171711
|
+
const adjusted = Math.max(0, toolCalls + delta);
|
|
171712
|
+
delta -= adjusted - toolCalls;
|
|
171713
|
+
toolCalls = adjusted;
|
|
171714
|
+
}
|
|
171715
|
+
}
|
|
171716
|
+
if (delta < 0) {
|
|
171717
|
+
const get = (name2) => {
|
|
171718
|
+
if (name2 === "system")
|
|
171719
|
+
return calibratedSystem;
|
|
171720
|
+
if (name2 === "toolDefs")
|
|
171721
|
+
return calibratedToolDefs;
|
|
171722
|
+
if (name2 === "compartments")
|
|
171723
|
+
return compartments;
|
|
171724
|
+
if (name2 === "facts")
|
|
171725
|
+
return facts;
|
|
171726
|
+
return memories;
|
|
171727
|
+
};
|
|
171728
|
+
const subtract = (name2, amount) => {
|
|
171729
|
+
if (name2 === "system")
|
|
171730
|
+
calibratedSystem -= amount;
|
|
171731
|
+
else if (name2 === "toolDefs")
|
|
171732
|
+
calibratedToolDefs -= amount;
|
|
171733
|
+
else if (name2 === "compartments")
|
|
171734
|
+
compartments -= amount;
|
|
171735
|
+
else if (name2 === "facts")
|
|
171736
|
+
facts -= amount;
|
|
171737
|
+
else
|
|
171738
|
+
memories -= amount;
|
|
171739
|
+
};
|
|
171740
|
+
const buckets = ["system", "toolDefs", "compartments", "facts", "memories"];
|
|
171741
|
+
buckets.sort((a, b) => get(b) - get(a));
|
|
171742
|
+
for (const name2 of buckets) {
|
|
171743
|
+
if (delta >= 0)
|
|
171744
|
+
break;
|
|
171745
|
+
const value = get(name2);
|
|
171746
|
+
if (value <= 0)
|
|
171747
|
+
continue;
|
|
171748
|
+
const adjustment = Math.min(value, -delta);
|
|
171749
|
+
subtract(name2, adjustment);
|
|
171750
|
+
delta += adjustment;
|
|
171751
|
+
}
|
|
171752
|
+
}
|
|
171753
|
+
return {
|
|
171754
|
+
systemTokens: calibratedSystem,
|
|
171755
|
+
toolDefinitionTokens: calibratedToolDefs,
|
|
171756
|
+
compartmentTokens: compartments,
|
|
171757
|
+
factTokens: facts,
|
|
171758
|
+
memoryTokens: memories,
|
|
171759
|
+
conversationTokens: conversation,
|
|
171760
|
+
toolCallTokens: toolCalls
|
|
171761
|
+
};
|
|
171762
|
+
}
|
|
171763
|
+
|
|
171764
|
+
// src/plugin/rpc-handlers.ts
|
|
171511
171765
|
init_logger();
|
|
171512
171766
|
init_rpc_notifications();
|
|
171513
171767
|
function getDb() {
|
|
@@ -171577,8 +171831,7 @@ function buildSidebarSnapshot(db, sessionId, directory, liveSessionState) {
|
|
|
171577
171831
|
memoryTokens: 0,
|
|
171578
171832
|
conversationTokens: 0,
|
|
171579
171833
|
toolCallTokens: 0,
|
|
171580
|
-
toolDefinitionTokens: 0
|
|
171581
|
-
overheadTokens: 0
|
|
171834
|
+
toolDefinitionTokens: 0
|
|
171582
171835
|
};
|
|
171583
171836
|
try {
|
|
171584
171837
|
const projectIdentity = resolveProjectIdentity(directory);
|
|
@@ -171652,23 +171905,37 @@ ${c.content}
|
|
|
171652
171905
|
} catch {}
|
|
171653
171906
|
}
|
|
171654
171907
|
const injectedInMessages = compartmentTokens + factTokens + memoryTokens;
|
|
171655
|
-
const
|
|
171656
|
-
const
|
|
171908
|
+
const conversationLocal = Math.max(0, messagesBlockTokens - injectedInMessages);
|
|
171909
|
+
const toolCallsLocal = Math.max(0, toolCallTokensRaw);
|
|
171657
171910
|
let measuredToolDefTokens = 0;
|
|
171911
|
+
let activeProviderID;
|
|
171912
|
+
let activeModelID;
|
|
171658
171913
|
if (liveSessionState) {
|
|
171659
171914
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
171660
171915
|
const agent = liveSessionState.agentBySession.get(sessionId);
|
|
171661
171916
|
if (model) {
|
|
171917
|
+
activeProviderID = model.providerID;
|
|
171918
|
+
activeModelID = model.modelID;
|
|
171662
171919
|
measuredToolDefTokens = getMeasuredToolDefinitionTokens(model.providerID, model.modelID, agent) ?? 0;
|
|
171663
171920
|
}
|
|
171664
171921
|
}
|
|
171665
|
-
const
|
|
171666
|
-
const
|
|
171667
|
-
|
|
171922
|
+
const calibration = resolveModelCalibration(activeProviderID, activeModelID);
|
|
171923
|
+
const calibrated = calibrateBuckets({
|
|
171924
|
+
inputTokens,
|
|
171925
|
+
systemLocal: systemPromptTokens,
|
|
171926
|
+
toolDefsLocal: measuredToolDefTokens,
|
|
171927
|
+
compartmentsLocal: compartmentTokens,
|
|
171928
|
+
factsLocal: factTokens,
|
|
171929
|
+
memoriesLocal: memoryTokens,
|
|
171930
|
+
conversationLocal,
|
|
171931
|
+
toolCallsLocal,
|
|
171932
|
+
calibration
|
|
171933
|
+
});
|
|
171934
|
+
const fresh = {
|
|
171668
171935
|
sessionId,
|
|
171669
171936
|
usagePercentage,
|
|
171670
171937
|
inputTokens,
|
|
171671
|
-
systemPromptTokens,
|
|
171938
|
+
systemPromptTokens: calibrated.systemTokens,
|
|
171672
171939
|
compartmentCount,
|
|
171673
171940
|
factCount,
|
|
171674
171941
|
memoryCount,
|
|
@@ -171681,14 +171948,14 @@ ${c.content}
|
|
|
171681
171948
|
cacheTtl,
|
|
171682
171949
|
lastDreamerRunAt,
|
|
171683
171950
|
projectIdentity,
|
|
171684
|
-
compartmentTokens,
|
|
171685
|
-
factTokens,
|
|
171686
|
-
memoryTokens,
|
|
171687
|
-
conversationTokens,
|
|
171688
|
-
toolCallTokens,
|
|
171689
|
-
toolDefinitionTokens
|
|
171690
|
-
overheadTokens
|
|
171951
|
+
compartmentTokens: calibrated.compartmentTokens,
|
|
171952
|
+
factTokens: calibrated.factTokens,
|
|
171953
|
+
memoryTokens: calibrated.memoryTokens,
|
|
171954
|
+
conversationTokens: calibrated.conversationTokens,
|
|
171955
|
+
toolCallTokens: calibrated.toolCallTokens,
|
|
171956
|
+
toolDefinitionTokens: calibrated.toolDefinitionTokens
|
|
171691
171957
|
};
|
|
171958
|
+
return applyStickySnapshotCache(sessionId, fresh);
|
|
171692
171959
|
} catch (err) {
|
|
171693
171960
|
log("[rpc] sidebar-snapshot error:", err);
|
|
171694
171961
|
return empty;
|
|
@@ -171860,7 +172127,13 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
171860
172127
|
historianChunkTokens,
|
|
171861
172128
|
historianTimeoutMs: config2.historian_timeout_ms ?? DEFAULT_HISTORIAN_TIMEOUT_MS2,
|
|
171862
172129
|
directory,
|
|
171863
|
-
|
|
172130
|
+
memoryEnabled: config2.memory?.enabled,
|
|
172131
|
+
autoPromote: config2.memory?.auto_promote ?? true,
|
|
172132
|
+
getNotificationParams: () => getNotificationParams(sessionId),
|
|
172133
|
+
onInjectionCacheCleared: (sid) => {
|
|
172134
|
+
liveSessionState.historyRefreshSessions.add(sid);
|
|
172135
|
+
liveSessionState.pendingMaterializationSessions.add(sid);
|
|
172136
|
+
}
|
|
171864
172137
|
}).then((result) => {
|
|
171865
172138
|
sendIgnoredMessage2(args.client, sessionId, result, getNotificationParams(sessionId)).catch(() => {});
|
|
171866
172139
|
}).catch((error48) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-session-hooks.d.ts","sourceRoot":"","sources":["../../../src/plugin/hooks/create-session-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAU7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,GAAG,EAAE,aAAa,CAAC;IACnB,YAAY,EAAE,wBAAwB,CAAC;IACvC,gBAAgB,EAAE,gBAAgB,CAAC;CACtC;;;;;;
|
|
1
|
+
{"version":3,"file":"create-session-hooks.d.ts","sourceRoot":"","sources":["../../../src/plugin/hooks/create-session-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAU7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,GAAG,EAAE,aAAa,CAAC;IACnB,YAAY,EAAE,wBAAwB,CAAC;IACvC,gBAAgB,EAAE,gBAAgB,CAAC;CACtC;;;;;;qBAmDu0E,CAAC;;;;;;;;;;;;qBAAqd,CAAC;mBAAyB,CAAC;iBAAuB,CAAC;iBAAuB,CAAC;0BAAc,CAAC;uBAAiB,CAAC;;;;;;0BAAi+mB,CAAC;;;;;;EAD32sB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-handlers.d.ts","sourceRoot":"","sources":["../../src/plugin/rpc-handlers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAMzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"rpc-handlers.d.ts","sourceRoot":"","sources":["../../src/plugin/rpc-handlers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAMzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAQlF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAkflE;;GAEG;AACH,wBAAgB,mBAAmB,CAC/B,SAAS,EAAE,qBAAqB,EAChC,IAAI,EAAE;IACF,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,gBAAgB,EAAE,gBAAgB,CAAC;CACtC,GACF,IAAI,CA8HN"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SidebarSnapshot } from "../shared/rpc-types";
|
|
2
|
+
/**
|
|
3
|
+
* Apply the sticky-cache policy to a freshly built snapshot.
|
|
4
|
+
*
|
|
5
|
+
* Returns either the live snapshot (preferred) or a hybrid snapshot that
|
|
6
|
+
* preserves token-breakdown values from the previous good reading while keeping
|
|
7
|
+
* fresh DB-backed counts (compartmentCount, memoryCount, historian state, etc.)
|
|
8
|
+
* from the current build.
|
|
9
|
+
*/
|
|
10
|
+
export declare function applyStickySnapshotCache(sessionId: string, fresh: SidebarSnapshot): SidebarSnapshot;
|
|
11
|
+
/**
|
|
12
|
+
* Drop the cached snapshot for a session. Wired to `session.deleted`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function clearSidebarSnapshotCache(sessionId: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Test helper — drop the entire cache.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resetSidebarSnapshotCache(): void;
|
|
19
|
+
//# sourceMappingURL=sidebar-snapshot-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidebar-snapshot-cache.d.ts","sourceRoot":"","sources":["../../src/plugin/sidebar-snapshot-cache.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAY3D;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACpC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,eAAe,GACvB,eAAe,CAsCjB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAEjE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD"}
|
|
@@ -43,15 +43,6 @@ export interface SidebarSnapshot {
|
|
|
43
43
|
* shows this as "Tool Definitions".
|
|
44
44
|
*/
|
|
45
45
|
toolDefinitionTokens: number;
|
|
46
|
-
/**
|
|
47
|
-
* Residual catch-all: provider-side wrapping not captured elsewhere —
|
|
48
|
-
* the JSON envelope around the `tools` array, tool-choice fields,
|
|
49
|
-
* provider-specific cache-control markers, tokenizer imprecision, etc.
|
|
50
|
-
* Computed as `inputTokens − systemPromptTokens − messagesBlock −
|
|
51
|
-
* toolCallTokens − toolDefinitionTokens` and clamped to ≥ 0. Display
|
|
52
|
-
* layer shows this as "Overhead".
|
|
53
|
-
*/
|
|
54
|
-
overheadTokens: number;
|
|
55
46
|
}
|
|
56
47
|
export interface StatusDetail extends SidebarSnapshot {
|
|
57
48
|
tagCounter: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-types.d.ts","sourceRoot":"","sources":["../../src/shared/rpc-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,eAAe;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;;;;;OAOG;IACH,oBAAoB,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"rpc-types.d.ts","sourceRoot":"","sources":["../../src/shared/rpc-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,eAAe;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;;;;;OAOG;IACH,oBAAoB,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,YAAa,SAAQ,eAAe;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,oBAAoB,EAAE,YAAY,GAAG,QAAQ,CAAC;IAC9C;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,EAAE,MAAM,CAAC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,sBAAsB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB"}
|