billion-context-pi 0.1.61 → 0.1.62-pr.347.141

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/config.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type Config, type Prompts } from "acp-kernel";
2
+ import type { CompressReasoningConfig } from "./reasoning-drop.js";
2
3
  import type { ThrottleRetryConfig } from "./throttle-retry.js";
3
4
  /** Per-role delegate defaults. Lets long-lived automation pin a cheaper or
4
5
  * more capable model and a thinking level per delegate role, so the main
@@ -114,6 +115,10 @@ export interface CompressSettings {
114
115
  * window and would suppress every nudge. Maps to kernel
115
116
  * nudge.minPressureBenefitTokens. */
116
117
  minPressureBenefitTokens?: number;
118
+ /** [#336] Drop oversized reasoning (thinking) from historical `compress`
119
+ * tool calls — see CompressReasoningConfig in src/reasoning-drop.ts.
120
+ * Merged field-wise (drop, threshold) across the three levels. */
121
+ reasoning?: CompressReasoningConfig;
117
122
  }
118
123
  /** Per-provider compression overrides. Carries the same tuning fields as the
119
124
  * global level, plus an optional per-model map keyed by model id. */
package/dist/index.js CHANGED
@@ -3911,7 +3911,11 @@ function mergeCompress(global, provider, model) {
3911
3911
  maxContextLimit: model?.maxContextLimit ?? provider?.maxContextLimit ?? global?.maxContextLimit,
3912
3912
  emergencyThresholdPercent: model?.emergencyThresholdPercent ?? provider?.emergencyThresholdPercent ?? global?.emergencyThresholdPercent,
3913
3913
  nudgeGrowthTokens: model?.nudgeGrowthTokens ?? provider?.nudgeGrowthTokens ?? global?.nudgeGrowthTokens,
3914
- minPressureBenefitTokens: model?.minPressureBenefitTokens ?? provider?.minPressureBenefitTokens ?? global?.minPressureBenefitTokens
3914
+ minPressureBenefitTokens: model?.minPressureBenefitTokens ?? provider?.minPressureBenefitTokens ?? global?.minPressureBenefitTokens,
3915
+ reasoning: {
3916
+ drop: model?.reasoning?.drop ?? provider?.reasoning?.drop ?? global?.reasoning?.drop,
3917
+ threshold: model?.reasoning?.threshold ?? provider?.reasoning?.threshold ?? global?.reasoning?.threshold
3918
+ }
3915
3919
  };
3916
3920
  }
3917
3921
  function resolveCompress(compress, provider, modelId) {
@@ -3953,6 +3957,63 @@ function parsePercent(v2) {
3953
3957
  return Number(s);
3954
3958
  }
3955
3959
 
3960
+ // src/reasoning-drop.ts
3961
+ var DEFAULT_COMPRESS_REASONING = { drop: true, threshold: 2048 };
3962
+ function resolveReasoningDrop(cfg) {
3963
+ let threshold = DEFAULT_COMPRESS_REASONING.threshold;
3964
+ if (cfg?.threshold !== void 0) {
3965
+ const t = cfg.threshold;
3966
+ if (typeof t === "number" && Number.isFinite(t) && t >= 0) {
3967
+ threshold = Math.floor(t);
3968
+ } else {
3969
+ logWarn("config", { event: "compress-reasoning-invalid", field: "threshold", value: t, fallback: DEFAULT_COMPRESS_REASONING.threshold });
3970
+ }
3971
+ }
3972
+ return { drop: cfg?.drop !== false, threshold };
3973
+ }
3974
+ function isThinking(part) {
3975
+ const p = part;
3976
+ return p?.type === "thinking" && typeof p.thinking === "string";
3977
+ }
3978
+ function hasCompressCall(content) {
3979
+ if (!Array.isArray(content)) return false;
3980
+ return content.some((p) => {
3981
+ const b2 = p;
3982
+ return b2?.type === "toolCall" && b2.name === "compress";
3983
+ });
3984
+ }
3985
+ function reasoningLength(content) {
3986
+ if (!Array.isArray(content)) return 0;
3987
+ return content.reduce((n, p) => isThinking(p) ? n + p.thinking.length : n, 0);
3988
+ }
3989
+ function dropCompressReasoning(messages, cfg) {
3990
+ const { drop, threshold } = resolveReasoningDrop(cfg);
3991
+ if (!drop || messages.length === 0) return messages;
3992
+ try {
3993
+ let lastUser = -1;
3994
+ for (let i = 0; i < messages.length; i++) {
3995
+ if (messages[i].role === "user") lastUser = i;
3996
+ }
3997
+ if (lastUser < 0) return messages;
3998
+ let changed = false;
3999
+ const out = messages.slice();
4000
+ for (let i = 0; i < lastUser; i++) {
4001
+ const msg = messages[i];
4002
+ if (msg.role !== "assistant" || !Array.isArray(msg.content)) continue;
4003
+ if (!hasCompressCall(msg.content)) continue;
4004
+ if (reasoningLength(msg.content) <= threshold) continue;
4005
+ out[i] = {
4006
+ ...msg,
4007
+ content: msg.content.filter((p) => !isThinking(p))
4008
+ };
4009
+ changed = true;
4010
+ }
4011
+ return changed ? out : messages;
4012
+ } catch {
4013
+ return messages;
4014
+ }
4015
+ }
4016
+
3956
4017
  // src/tag-tokens.ts
3957
4018
  function formatTokens3(tokens) {
3958
4019
  if (tokens < 1e3) return String(tokens);
@@ -5175,6 +5236,10 @@ function createRuntime(adapter) {
5175
5236
  const m2 = ctx.model;
5176
5237
  return resolveConfig(adapterRef, liveContextLimit(ctx), m2?.provider, m2?.id);
5177
5238
  }
5239
+ function reasoningDropFor(ctx) {
5240
+ const m2 = ctx.model;
5241
+ return resolveReasoningDrop(resolveCompress(adapterRef.compress, m2?.provider, m2?.id).reasoning);
5242
+ }
5178
5243
  async function reloadConfig(cwd) {
5179
5244
  let user;
5180
5245
  try {
@@ -5253,7 +5318,7 @@ function createRuntime(adapter) {
5253
5318
  }, nudgeShownFor: (k) => nudgeShownTurns.has(k), nudgeShownTokensFor: (k) => nudgeShownTokens.get(k), clearNudgeTracking: () => {
5254
5319
  nudgeShownTurns.clear();
5255
5320
  nudgeShownTokens.clear();
5256
- }, clearNudgeTokenStamps: () => nudgeShownTokens.clear(), noteCompressOutcomes, compressRetryCappedFor, clearCompressRetryTracking, liveContextLimit, configFor, reloadConfig, stateFor, save, acquireLock, overflowFor, overflowDrop, noteDeadCompress, clearDeadCompress, throttleFor, throttleDrop, noteTokenScale, dropTokenScale };
5321
+ }, clearNudgeTokenStamps: () => nudgeShownTokens.clear(), noteCompressOutcomes, compressRetryCappedFor, clearCompressRetryTracking, liveContextLimit, configFor, reasoningDropFor, reloadConfig, stateFor, save, acquireLock, overflowFor, overflowDrop, noteDeadCompress, clearDeadCompress, throttleFor, throttleDrop, noteTokenScale, dropTokenScale };
5257
5322
  }
5258
5323
 
5259
5324
  // node_modules/typebox/build/system/memory/memory.mjs
@@ -16749,7 +16814,7 @@ async function statusReport(runtime, ctx) {
16749
16814
  const sentTokens = estimateTokens(coreMessages, coveredIds, imageTokens) + systemPromptTokens;
16750
16815
  const viewSentTokens = adjustedTokenCount(runtime.core, coreMessages, state, config, sentTokens, imageTokens, systemPromptTokens);
16751
16816
  const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount: anchorStale ? viewSentTokens : Math.max(viewSentTokens, realUsage?.tokens ?? 0) });
16752
- const versionStr = "0.1.61" ? `billion-context-pi@${"0.1.61"}` : void 0;
16817
+ const versionStr = "0.1.62" ? `billion-context-pi@${"0.1.62"}` : void 0;
16753
16818
  let text = buildStatusPanel({
16754
16819
  version: versionStr,
16755
16820
  tokenCount: sessionTokens,
@@ -17283,7 +17348,7 @@ async function autoInstallLatest(latest, extDirOverride) {
17283
17348
  "--no-fund",
17284
17349
  "--no-save"
17285
17350
  ];
17286
- const prevVersion = (await readPackageJson(join11(extDir, "package.json")))?.version ?? "0.1.61";
17351
+ const prevVersion = (await readPackageJson(join11(extDir, "package.json")))?.version ?? "0.1.62";
17287
17352
  const { code, stderr } = await runNpmImpl(installArgs(latest), { cwd: npmDir, timeout: 6e4 });
17288
17353
  if (code !== 0) {
17289
17354
  logWarn("update", {
@@ -17301,7 +17366,7 @@ async function autoInstallLatest(latest, extDirOverride) {
17301
17366
  }
17302
17367
  const verify = await verifyInstall(npmDir, latest);
17303
17368
  if (!verify.ok) {
17304
- const rollbackTo = SEMVER_RE.test(prevVersion) ? prevVersion : "0.1.61";
17369
+ const rollbackTo = SEMVER_RE.test(prevVersion) ? prevVersion : "0.1.62";
17305
17370
  logWarn("update", { event: "auto-install-verify-failed", latest, reason: verify.reason, rollbackTo });
17306
17371
  const rb = await runNpmImpl(installArgs(rollbackTo), { cwd: npmDir, timeout: 6e4 });
17307
17372
  logInfo("update", { event: "rollback", from: latest, to: rollbackTo, ok: rb.code === 0 });
@@ -17376,7 +17441,7 @@ async function checkForUpdate(autoUpdate, notify) {
17376
17441
  }
17377
17442
  const latest = await fetchLatestVersion(tag);
17378
17443
  if (!latest) return;
17379
- const current = runtimeVersion ?? "0.1.61";
17444
+ const current = runtimeVersion ?? "0.1.62";
17380
17445
  const hasUpdate = isVersionNewer(latest, current);
17381
17446
  debug.event("update-check", {
17382
17447
  current,
@@ -17554,7 +17619,7 @@ function wireSessionLifecycle(pi, runtime, standDownIfProxied) {
17554
17619
  setDelegatePolicy(DEFAULT_DELEGATE_POLICY);
17555
17620
  const sid = ctx.sessionManager.getSessionId();
17556
17621
  const modelInfo = ctx.model;
17557
- logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.61" : null, model: modelInfo?.id ?? null, modelApi: modelInfo?.api ?? null, contextWindow: modelInfo?.contextWindow ?? null });
17622
+ logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.62" : null, model: modelInfo?.id ?? null, modelApi: modelInfo?.api ?? null, contextWindow: modelInfo?.contextWindow ?? null });
17558
17623
  try {
17559
17624
  await runtime.reloadConfig(ctx.cwd);
17560
17625
  const delegateCfg = resolveDelegate(runtime.adapter);
@@ -17701,7 +17766,13 @@ function wireContextTransform(pi, runtime, standDownIfProxied) {
17701
17766
  activeAfter: turn.state.blocks.filter((b2) => b2.active).length
17702
17767
  });
17703
17768
  const originalById = collectOriginals(entries);
17704
- const rebuilt = coreOutToAgentMessages(turn.messages, originalById);
17769
+ let rebuilt = coreOutToAgentMessages(turn.messages, originalById);
17770
+ const reasoningDrop = runtime.reasoningDropFor(ctx);
17771
+ const droppedThinking = dropCompressReasoning(rebuilt, reasoningDrop);
17772
+ if (droppedThinking !== rebuilt) {
17773
+ debug.event("reasoning-drop", { sid, dropped: droppedThinking.length, drop: reasoningDrop.drop, threshold: reasoningDrop.threshold });
17774
+ }
17775
+ rebuilt = droppedThinking;
17705
17776
  const debugOn2 = debug.enabled;
17706
17777
  const turnKey = lastUserMessageId(entries) ?? sid;
17707
17778
  const compressOutcomes = collectCompressOutcomes(entries, turnStartIndex(entries));