billion-context-pi 0.1.78-pr.328.366 → 0.1.78-pr.355.367

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.
@@ -1,4 +1,3 @@
1
- import type { CompressionBlock } from "acp-kernel";
2
1
  type UsageLike = {
3
2
  totalTokens?: number;
4
3
  input?: number;
@@ -23,9 +22,4 @@ type AnchorEntry = {
23
22
  * still reflects the pre-compression request. Failed/no-op compresses don't
24
23
  * count (nothing was reclaimed). */
25
24
  export declare function usageAnchorPredatesCompression(entries: AnchorEntry[]): boolean;
26
- export interface AnchorStaleness {
27
- predates: boolean;
28
- netReclaimed: number;
29
- }
30
- export declare function compressionAnchorStaleness(entries: AnchorEntry[], blocks: readonly CompressionBlock[], countTokens: (text: string) => number): AnchorStaleness;
31
25
  export {};
package/dist/index.js CHANGED
@@ -15153,10 +15153,9 @@ function validAnchorUsage(u) {
15153
15153
  const total = (u.totalTokens ?? 0) || (u.input ?? 0) + (u.output ?? 0) + (u.cacheRead ?? 0) + (u.cacheWrite ?? 0);
15154
15154
  return total > 0;
15155
15155
  }
15156
- function scanEntries(entries) {
15156
+ function usageAnchorPredatesCompression(entries) {
15157
15157
  let lastUsageIdx = -1;
15158
15158
  let lastCompressIdx = -1;
15159
- const compressIdxByCallId = /* @__PURE__ */ new Map();
15160
15159
  for (let i = 0; i < entries.length; i++) {
15161
15160
  const m2 = entries[i].message;
15162
15161
  if (!m2) continue;
@@ -15164,26 +15163,9 @@ function scanEntries(entries) {
15164
15163
  lastUsageIdx = i;
15165
15164
  } else if (m2.role === "toolResult" && m2.toolName === "compress" && m2.toolCallId !== void 0 && m2.isError !== true && isCompressSuccessText(extractText(m2.content))) {
15166
15165
  lastCompressIdx = i;
15167
- compressIdxByCallId.set(m2.toolCallId, i);
15168
15166
  }
15169
15167
  }
15170
- return { lastUsageIdx, lastCompressIdx, compressIdxByCallId };
15171
- }
15172
- function usageAnchorPredatesCompression(entries) {
15173
- const scan = scanEntries(entries);
15174
- return scan.lastCompressIdx > scan.lastUsageIdx;
15175
- }
15176
- function compressionAnchorStaleness(entries, blocks, countTokens) {
15177
- const scan = scanEntries(entries);
15178
- let netReclaimed = 0;
15179
- for (const block of blocks) {
15180
- if (!block.active || block.compressCallId == null) continue;
15181
- const idx = scan.compressIdxByCallId.get(block.compressCallId);
15182
- if (idx == null || idx <= scan.lastUsageIdx) continue;
15183
- const saved = (block.compressedTokens ?? 0) - countTokens(block.summary ?? "");
15184
- netReclaimed += saved > 0 ? saved : 0;
15185
- }
15186
- return { predates: scan.lastCompressIdx > scan.lastUsageIdx, netReclaimed };
15168
+ return lastCompressIdx > lastUsageIdx;
15187
15169
  }
15188
15170
 
15189
15171
  // src/delegate-tool.ts
@@ -23260,12 +23242,11 @@ function wireContextTransform(pi, runtime, standDownIfProxied) {
23260
23242
  armedFloor = Math.floor(config.modelContextLimit * 0.95);
23261
23243
  logWarn("overflow-selfheal", { sid, event: "armed-emergency", floor: armedFloor, limit: config.modelContextLimit });
23262
23244
  }
23263
- const { predates, netReclaimed } = compressionAnchorStaleness(entries, state.blocks, defaultCountTokens);
23245
+ const hostFloorActive = !usageAnchorPredatesCompression(entries);
23264
23246
  const realPromptTokens = realUsage?.tokens ?? 0;
23265
- const hostFloor = realPromptTokens > 0 ? Math.max(0, realPromptTokens - (predates ? netReclaimed : 0)) : 0;
23266
- const hostUsageStable = !predates && realPromptTokens > 0 ? runtime.noteHostUsage(sid, realPromptTokens) : false;
23247
+ const hostUsageStable = hostFloorActive && realPromptTokens > 0 ? runtime.noteHostUsage(sid, realPromptTokens) : false;
23267
23248
  const calibrate = (base) => hostUsageStable ? Math.min(base, Math.ceil(realPromptTokens * 1.2)) : base;
23268
- const applyFloors = (base) => Math.max(calibrate(base), hostFloor, armedFloor);
23249
+ const applyFloors = (base) => Math.max(calibrate(base), hostFloorActive ? realPromptTokens : 0, armedFloor);
23269
23250
  let tokenCount = applyFloors(sentTokens);
23270
23251
  if (state.blocks.some((b2) => b2.active && b2.effectiveMessageIds.length > 0)) {
23271
23252
  const view = sentViewTokenCount(runtime.core, coreMessages, state, config, tokenCount, imageTokens, systemPromptTokens);
@@ -23274,11 +23255,11 @@ function wireContextTransform(pi, runtime, standDownIfProxied) {
23274
23255
  logInfo("turn", { sid, event: "view-recount", prelim: sentTokens, viewTokens: view.viewTokens, tokenCount });
23275
23256
  }
23276
23257
  }
23277
- const sizeDivergent = !predates && realPromptTokens > 0 && Math.abs(tokenCount - realPromptTokens) / realPromptTokens > 0.5;
23258
+ const sizeDivergent = hostFloorActive && realPromptTokens > 0 && Math.abs(tokenCount - realPromptTokens) / realPromptTokens > 0.5;
23278
23259
  if (runtime.noteSizeDivergence(sid, sizeDivergent)) {
23279
23260
  logWarn("turn", { sid, event: "size-divergence", est: tokenCount, host: realPromptTokens, ratio: Number((tokenCount / realPromptTokens).toFixed(2)), stable: hostUsageStable });
23280
23261
  }
23281
- if (runtime.noteTokenScale(sid, hostFloor <= sentTokens)) {
23262
+ if (runtime.noteTokenScale(sid, !hostFloorActive)) {
23282
23263
  state.nudge.lastNudgeShownTokens = state.nudge.lastNudgeShownTokens > 0 ? tokenCount : 0;
23283
23264
  state.nudge.lastPerMessageNudgeTokens = state.nudge.lastPerMessageNudgeTokens > 0 ? tokenCount : 0;
23284
23265
  const reanchored = {};
@@ -23287,7 +23268,7 @@ function wireContextTransform(pi, runtime, standDownIfProxied) {
23287
23268
  }
23288
23269
  state.nudge.lastShownByTier = reanchored;
23289
23270
  runtime.clearNudgeTokenStamps(sid);
23290
- logInfo("growth-scale", { sid, event: "scale-flip-reanchor", estScaleWins: hostFloor <= sentTokens, predates, tokenCount });
23271
+ logInfo("growth-scale", { sid, event: "scale-flip-reanchor", anchorStale: !hostFloorActive, tokenCount });
23291
23272
  }
23292
23273
  debug.event("context-in", {
23293
23274
  sid,