@cortexkit/pi-magic-context 0.49.45 → 0.49.46
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.
|
@@ -609,6 +609,11 @@ function deriveWindowGeometry(providerID, modelID, catalogLimit, options = {}) {
|
|
|
609
609
|
const requestedOutput = Math.min(output ?? OPENCODE_OUTPUT_CAP, OPENCODE_OUTPUT_CAP);
|
|
610
610
|
usableHard = hardWindow - requestedOutput;
|
|
611
611
|
}
|
|
612
|
+
let hardWithoutInputCap;
|
|
613
|
+
if (isFinitePositive(input) && input < usableHard) {
|
|
614
|
+
hardWithoutInputCap = Math.max(MIN_PLAUSIBLE_CONTEXT_LIMIT, Math.floor(usableHard));
|
|
615
|
+
usableHard = input;
|
|
616
|
+
}
|
|
612
617
|
usableHard = Math.max(MIN_PLAUSIBLE_CONTEXT_LIMIT, Math.floor(usableHard));
|
|
613
618
|
if (usableHard < usableSoft) {
|
|
614
619
|
logGeometryClampOnce(`${providerID}/${modelID}|${usableSoft}|${usableHard}`, `usable hard limit clamped for ${providerID}/${modelID}: ${usableHard} → ${usableSoft} (window limit inversion)`, options.log);
|
|
@@ -625,7 +630,8 @@ function deriveWindowGeometry(providerID, modelID, catalogLimit, options = {}) {
|
|
|
625
630
|
reserveSource,
|
|
626
631
|
geometry,
|
|
627
632
|
windowSource,
|
|
628
|
-
absoluteWall: Math.floor(hardWindow)
|
|
633
|
+
absoluteWall: Math.floor(hardWindow),
|
|
634
|
+
...hardWithoutInputCap !== undefined ? { hardWithoutInputCap } : {}
|
|
629
635
|
}
|
|
630
636
|
};
|
|
631
637
|
}
|
|
@@ -647,11 +653,13 @@ function applyProvenInputFloor(geometry, provenInputTokens) {
|
|
|
647
653
|
}
|
|
648
654
|
const trustedAbsoluteWall = hasTrustedAbsoluteWall(geometry);
|
|
649
655
|
const window = trustedAbsoluteWall ? geometry.derivation.window : Math.max(geometry.derivation.window, provenInputTokens);
|
|
656
|
+
const inputCapDisproved = geometry.derivation.hardWithoutInputCap !== undefined && provenInputTokens > geometry.usableHard;
|
|
657
|
+
const hardBeforeFloor = inputCapDisproved ? geometry.derivation.hardWithoutInputCap : geometry.usableHard;
|
|
650
658
|
return {
|
|
651
659
|
geometry: {
|
|
652
660
|
...geometry,
|
|
653
661
|
usableSoft: provenInputTokens,
|
|
654
|
-
usableHard: trustedAbsoluteWall ?
|
|
662
|
+
usableHard: trustedAbsoluteWall ? hardBeforeFloor : Math.max(hardBeforeFloor, provenInputTokens),
|
|
655
663
|
derivation: {
|
|
656
664
|
...geometry.derivation,
|
|
657
665
|
window,
|
|
@@ -7610,9 +7618,9 @@ var FULL_PARAMETER_DESCRIPTIONS = {
|
|
|
7610
7618
|
},
|
|
7611
7619
|
ctx_memory: {
|
|
7612
7620
|
action: "write | update | archive | merge | get",
|
|
7613
|
-
content: "The memory text — one standalone fact (write, update, merge).",
|
|
7614
|
-
category: "Kind of fact
|
|
7615
|
-
ids: "Memory ids from <project-memory>: one for update, one or more for archive, two or more for merge, 1–20 for get.",
|
|
7621
|
+
content: "The memory text — one standalone fact (write, update, merge). Archive and get take an empty string.",
|
|
7622
|
+
category: "Kind of fact: the new fact's kind for write; on update/merge, the memory's current category to keep it. Archive and get ignore it.",
|
|
7623
|
+
ids: "Memory ids from <project-memory>: one for update, one or more for archive, two or more for merge, 1–20 for get. Write takes an empty list.",
|
|
7616
7624
|
reason: "Why it is being archived (optional)."
|
|
7617
7625
|
},
|
|
7618
7626
|
ctx_search: {
|
|
@@ -7645,9 +7653,9 @@ var LIGHT_PARAMETER_DESCRIPTIONS = {
|
|
|
7645
7653
|
},
|
|
7646
7654
|
ctx_memory: {
|
|
7647
7655
|
action: "write | update | archive | merge | get",
|
|
7648
|
-
content: "One standalone fact (write, update, merge).",
|
|
7649
|
-
category: "Kind of fact (
|
|
7650
|
-
ids: "Ids from <project-memory>: one for update, 1+ for archive, 2+ for merge, 1–20 for get.",
|
|
7656
|
+
content: "One standalone fact (write, update, merge). Archive and get: empty string.",
|
|
7657
|
+
category: "Kind of fact (write; on update/merge pass the current category to keep it). Archive and get ignore it.",
|
|
7658
|
+
ids: "Ids from <project-memory>: one for update, 1+ for archive, 2+ for merge, 1–20 for get. Write: empty list.",
|
|
7651
7659
|
reason: "Why it is archived (optional)."
|
|
7652
7660
|
},
|
|
7653
7661
|
ctx_search: {
|
package/dist/index.js
CHANGED
|
@@ -150,7 +150,7 @@ import {
|
|
|
150
150
|
registerTodoStateLifecycle,
|
|
151
151
|
syncCtxMemoryToolEnabled,
|
|
152
152
|
registerMagicContextTools
|
|
153
|
-
} from "./index-
|
|
153
|
+
} from "./index-ewf0sd7d.js";
|
|
154
154
|
import"./index-4knyh1kt.js";
|
|
155
155
|
import {
|
|
156
156
|
canonicalModelIdentity,
|
|
@@ -3584,7 +3584,7 @@ function startHostStallProfilerSwitch() {
|
|
|
3584
3584
|
// package.json
|
|
3585
3585
|
var package_default = {
|
|
3586
3586
|
name: "@cortexkit/pi-magic-context",
|
|
3587
|
-
version: "0.49.
|
|
3587
|
+
version: "0.49.46",
|
|
3588
3588
|
type: "module",
|
|
3589
3589
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
3590
3590
|
main: "dist/index.js",
|
|
@@ -27374,6 +27374,19 @@ function opencodeReasoningBudgetStatus(messages, budget, prefixBound, proseRatio
|
|
|
27374
27374
|
};
|
|
27375
27375
|
}
|
|
27376
27376
|
|
|
27377
|
+
// ../plugin/src/hooks/magic-context/recovery-fit.ts
|
|
27378
|
+
var RECOVERY_REFUSAL_NOTICE = "Magic Context is still summarizing older history so this conversation fits the model's context window. Send your message again to continue.";
|
|
27379
|
+
var RECOVERY_NO_HISTORY_REFUSAL_NOTICE = "This conversation no longer fits the model's context window, and Magic Context has no more older history it can summarize. Switch to a model with a larger context window to continue.";
|
|
27380
|
+
function recoveryLineTokens(windowTokens) {
|
|
27381
|
+
return Math.floor(windowTokens * BLOCK_UNTIL_DONE_PERCENTAGE / 100);
|
|
27382
|
+
}
|
|
27383
|
+
function recoveryAdmissionLimitTokens(windowTokens, historyRemains) {
|
|
27384
|
+
return historyRemains ? recoveryLineTokens(windowTokens) : Math.floor(windowTokens);
|
|
27385
|
+
}
|
|
27386
|
+
function recoveryRefusalNotice(historyRemains) {
|
|
27387
|
+
return historyRemains ? RECOVERY_REFUSAL_NOTICE : RECOVERY_NO_HISTORY_REFUSAL_NOTICE;
|
|
27388
|
+
}
|
|
27389
|
+
|
|
27377
27390
|
// ../plugin/src/hooks/magic-context/signed-thinking-hold.ts
|
|
27378
27391
|
var HEAVY_REASONING_TOKENS = 1500;
|
|
27379
27392
|
var HEAVY_REASONING_WINDOW_STEPS = 15;
|
|
@@ -27854,7 +27867,7 @@ function resolveUnknownUsageFromWireEstimate(input) {
|
|
|
27854
27867
|
const providerLimit = input.providerProvenLimitTokens;
|
|
27855
27868
|
const canUseProviderMass = input.wireEstimateTrusted === false && typeof providerTokens === "number" && Number.isFinite(providerTokens) && providerTokens > 0 && typeof providerLimit === "number" && Number.isFinite(providerLimit) && providerLimit > 0;
|
|
27856
27869
|
const tokens = canUseProviderMass ? Math.max(wireTokens, providerTokens) : wireTokens;
|
|
27857
|
-
const limit = input.
|
|
27870
|
+
const limit = input.windowTokens;
|
|
27858
27871
|
const estimatedPercentage = typeof limit === "number" && Number.isFinite(limit) && limit > 0 ? tokens / limit * 100 : input.usage.percentage;
|
|
27859
27872
|
return {
|
|
27860
27873
|
inputTokens: tokens,
|
|
@@ -30825,8 +30838,6 @@ ${chunkText}`,
|
|
|
30825
30838
|
clearHistorianDrainFailure(db, sessionId);
|
|
30826
30839
|
recordProtectedTailPublicationFloor(db, sessionId, lastNewEnd + 1);
|
|
30827
30840
|
acknowledgePiHistoryRetirement(db, sessionId, lastNewEnd, (id) => provider.readMessages().find((message) => message.id === id)?.ordinal);
|
|
30828
|
-
if (!isWrapupInProgress(db, sessionId))
|
|
30829
|
-
clearEmergencyRecovery(db, sessionId);
|
|
30830
30841
|
if (lastNewEndMessageId) {
|
|
30831
30842
|
setPendingPiCompactionMarkerState(db, sessionId, {
|
|
30832
30843
|
firstKeptEntryId,
|
|
@@ -41903,7 +41914,7 @@ function piRecoveryToolImageTokens(messages) {
|
|
|
41903
41914
|
}
|
|
41904
41915
|
return counts;
|
|
41905
41916
|
}
|
|
41906
|
-
function estimatePiOverflowRecoveryInputTokens(messages, envelope) {
|
|
41917
|
+
function estimatePiOverflowRecoveryInputTokens(messages, envelope, options = {}) {
|
|
41907
41918
|
if (!envelope || !estimatePiOutgoingInputTokens([], envelope).trusted)
|
|
41908
41919
|
return;
|
|
41909
41920
|
const raw = tokenizePiMessages([...messages]);
|
|
@@ -41944,7 +41955,7 @@ function estimatePiOverflowRecoveryInputTokens(messages, envelope) {
|
|
|
41944
41955
|
system: envelope.systemTokens,
|
|
41945
41956
|
tools: envelope.toolDefinitionTokens + raw.toolCall,
|
|
41946
41957
|
prose: raw.conversation
|
|
41947
|
-
}, envelope.calibration ?? calibrationForModelKey(envelope.modelKey), true);
|
|
41958
|
+
}, envelope.calibration ?? calibrationForModelKey(envelope.modelKey), options.fitEnvelope ?? true);
|
|
41948
41959
|
}
|
|
41949
41960
|
function resolvePiOverflowRecoveryUsage(args) {
|
|
41950
41961
|
if (!args.pricedPass || !args.providerOverflow || args.usage.inputTokens > 0)
|
|
@@ -41953,7 +41964,7 @@ function resolvePiOverflowRecoveryUsage(args) {
|
|
|
41953
41964
|
usage: args.usage,
|
|
41954
41965
|
pricedPass: args.pricedPass,
|
|
41955
41966
|
wireEstimateTokens: estimatePiOverflowRecoveryInputTokens(args.messages, args.envelope),
|
|
41956
|
-
|
|
41967
|
+
windowTokens: args.usableHardLimit
|
|
41957
41968
|
});
|
|
41958
41969
|
}
|
|
41959
41970
|
|
|
@@ -44368,6 +44379,7 @@ function logPiLkgRecovery(sessionId, message) {
|
|
|
44368
44379
|
var PI_STABLE_ID_SCHEME = 1;
|
|
44369
44380
|
var lastEmergencyNotificationAtMs = new Map;
|
|
44370
44381
|
var EMERGENCY_NOTIFICATION_COOLDOWN_MS = 60000;
|
|
44382
|
+
var untrustedRecoveryCountLoggedSessions = new Set;
|
|
44371
44383
|
var commitSeenLastPass = new Map;
|
|
44372
44384
|
var historyRefreshSessions = new Set;
|
|
44373
44385
|
var systemPromptRefreshSessions = new Set;
|
|
@@ -47283,6 +47295,26 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
47283
47295
|
if (getHarness2() === "pi" && classifyPiOutgoingFit(estimate, outgoingFitLimit) === "over-window-proof")
|
|
47284
47296
|
throw new PiDegradedPassError("outgoing-over-window");
|
|
47285
47297
|
}
|
|
47298
|
+
const recoveryWindow = windowGeometry?.usableHard;
|
|
47299
|
+
const recoveryLatch = !options.compactionOff && isEmergency && emergencyRecoveryArmed && typeof recoveryWindow === "number" && recoveryWindow > 0 ? getOverflowState(options.db, sessionId) : undefined;
|
|
47300
|
+
if (recoveryLatch?.needsEmergencyRecovery === true && recoveryLatch.emergencyRecoveryOrigin !== null && typeof recoveryWindow === "number") {
|
|
47301
|
+
const served = estimatePiOverflowRecoveryInputTokens(outputMessages, readPiLkgFitEnvelope(ctx, pi, resolvePiContextModelKey(ctx), sessionDecisionCalibration(options.db, sessionId), toolWireSchema), { fitEnvelope: false });
|
|
47302
|
+
const historyRemains = inFlightHistorian.has(sessionId);
|
|
47303
|
+
const limit = recoveryAdmissionLimitTokens(recoveryWindow, historyRemains);
|
|
47304
|
+
if (served !== undefined && served > limit) {
|
|
47305
|
+
sessionLog2(sessionId, historyRemains ? `transform: recovery request still over the window: about ${served} tokens against the 95% line ${limit} of ${recoveryWindow}; not sending it, recovery stays armed for the next turn` : `transform: recovery request still over the window: about ${served} tokens against the whole window ${limit}, with no older history left to summarize; not sending it`);
|
|
47306
|
+
throw contextRefusalError(recoveryRefusalNotice(historyRemains));
|
|
47307
|
+
}
|
|
47308
|
+
if (served === undefined) {
|
|
47309
|
+
if (!untrustedRecoveryCountLoggedSessions.has(sessionId)) {
|
|
47310
|
+
untrustedRecoveryCountLoggedSessions.add(sessionId);
|
|
47311
|
+
sessionLog2(sessionId, "transform: recovery request not counted: the fit envelope is untrusted (system prompt or tool definitions not measured yet), so only the byte-count check above applies");
|
|
47312
|
+
}
|
|
47313
|
+
} else {
|
|
47314
|
+
clearEmergencyRecovery(options.db, sessionId);
|
|
47315
|
+
sessionLog2(sessionId, `transform: recovery request admitted: about ${served} tokens, within ${limit} of ${recoveryWindow}; ${recoveryLatch.emergencyRecoveryOrigin} recovery ends`);
|
|
47316
|
+
}
|
|
47317
|
+
}
|
|
47286
47318
|
publishFinalRequestAccounting();
|
|
47287
47319
|
let serializedOutput;
|
|
47288
47320
|
let numbersCommitted = false;
|
|
@@ -49951,6 +49983,7 @@ function clearContextHandlerSession(sessionId) {
|
|
|
49951
49983
|
activeContextHandlerSessions.delete(sessionId);
|
|
49952
49984
|
clearAutoSearchForPiSession(sessionId);
|
|
49953
49985
|
lastEmergencyNotificationAtMs.delete(sessionId);
|
|
49986
|
+
untrustedRecoveryCountLoggedSessions.delete(sessionId);
|
|
49954
49987
|
historyRefreshSessions.delete(sessionId);
|
|
49955
49988
|
clearPendingMaterialization(pendingMaterializationSessions, sessionId);
|
|
49956
49989
|
systemPromptRefreshSessions.delete(sessionId);
|
package/dist/subagent-entry.js
CHANGED
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
ensureProjectRegisteredFromPiDirectory,
|
|
35
35
|
resolvePiHarnessKind,
|
|
36
36
|
registerMagicContextTools
|
|
37
|
-
} from "./index-
|
|
37
|
+
} from "./index-ewf0sd7d.js";
|
|
38
38
|
import"./index-gzk7d940.js";
|
|
39
39
|
import"./index-gwvahsdz.js";
|
|
40
40
|
import"./index-4sa1rx3h.js";
|
package/package.json
CHANGED