billion-context-pi 0.1.61 → 0.1.62-pr.349.142
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 +5 -0
- package/dist/index.js +98 -8
- package/dist/index.js.map +1 -1
- package/dist/reasoning-drop.d.ts +46 -0
- package/dist/runtime.d.ts +5 -0
- package/package.json +1 -1
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,82 @@ 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 compressCallIds(content) {
|
|
3986
|
+
if (!Array.isArray(content)) return [];
|
|
3987
|
+
return content.filter((p) => {
|
|
3988
|
+
const b2 = p;
|
|
3989
|
+
return b2?.type === "toolCall" && b2.name === "compress";
|
|
3990
|
+
}).map((p) => p.id).filter((id) => typeof id === "string");
|
|
3991
|
+
}
|
|
3992
|
+
function resultIndexByCallId(messages) {
|
|
3993
|
+
const map = /* @__PURE__ */ new Map();
|
|
3994
|
+
for (let i = 0; i < messages.length; i++) {
|
|
3995
|
+
const msg = messages[i];
|
|
3996
|
+
if (msg?.role !== "toolResult" || typeof msg.toolCallId !== "string") continue;
|
|
3997
|
+
if (!map.has(msg.toolCallId)) map.set(msg.toolCallId, i);
|
|
3998
|
+
}
|
|
3999
|
+
return map;
|
|
4000
|
+
}
|
|
4001
|
+
function reasoningLength(content) {
|
|
4002
|
+
if (!Array.isArray(content)) return 0;
|
|
4003
|
+
return content.reduce((n, p) => isThinking(p) ? n + p.thinking.length : n, 0);
|
|
4004
|
+
}
|
|
4005
|
+
function dropCompressReasoning(messages, cfg) {
|
|
4006
|
+
const { drop, threshold } = resolveReasoningDrop(cfg);
|
|
4007
|
+
if (!drop || messages.length === 0) return messages;
|
|
4008
|
+
try {
|
|
4009
|
+
const last = messages.length - 1;
|
|
4010
|
+
const resultAt = resultIndexByCallId(messages);
|
|
4011
|
+
let changed = false;
|
|
4012
|
+
const out = messages.slice();
|
|
4013
|
+
for (let i = 0; i <= last; i++) {
|
|
4014
|
+
const msg = messages[i];
|
|
4015
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.content)) continue;
|
|
4016
|
+
if (!hasCompressCall(msg.content)) continue;
|
|
4017
|
+
const ids = compressCallIds(msg.content);
|
|
4018
|
+
const closed = ids.length > 0 && ids.every((id) => {
|
|
4019
|
+
const ri = resultAt.get(id);
|
|
4020
|
+
return ri !== void 0 && ri > i && ri < last;
|
|
4021
|
+
});
|
|
4022
|
+
if (!closed) continue;
|
|
4023
|
+
if (reasoningLength(msg.content) <= threshold) continue;
|
|
4024
|
+
out[i] = {
|
|
4025
|
+
...msg,
|
|
4026
|
+
content: msg.content.filter((p) => !isThinking(p))
|
|
4027
|
+
};
|
|
4028
|
+
changed = true;
|
|
4029
|
+
}
|
|
4030
|
+
return changed ? out : messages;
|
|
4031
|
+
} catch {
|
|
4032
|
+
return messages;
|
|
4033
|
+
}
|
|
4034
|
+
}
|
|
4035
|
+
|
|
3956
4036
|
// src/tag-tokens.ts
|
|
3957
4037
|
function formatTokens3(tokens) {
|
|
3958
4038
|
if (tokens < 1e3) return String(tokens);
|
|
@@ -5175,6 +5255,10 @@ function createRuntime(adapter) {
|
|
|
5175
5255
|
const m2 = ctx.model;
|
|
5176
5256
|
return resolveConfig(adapterRef, liveContextLimit(ctx), m2?.provider, m2?.id);
|
|
5177
5257
|
}
|
|
5258
|
+
function reasoningDropFor(ctx) {
|
|
5259
|
+
const m2 = ctx.model;
|
|
5260
|
+
return resolveReasoningDrop(resolveCompress(adapterRef.compress, m2?.provider, m2?.id).reasoning);
|
|
5261
|
+
}
|
|
5178
5262
|
async function reloadConfig(cwd) {
|
|
5179
5263
|
let user;
|
|
5180
5264
|
try {
|
|
@@ -5253,7 +5337,7 @@ function createRuntime(adapter) {
|
|
|
5253
5337
|
}, nudgeShownFor: (k) => nudgeShownTurns.has(k), nudgeShownTokensFor: (k) => nudgeShownTokens.get(k), clearNudgeTracking: () => {
|
|
5254
5338
|
nudgeShownTurns.clear();
|
|
5255
5339
|
nudgeShownTokens.clear();
|
|
5256
|
-
}, clearNudgeTokenStamps: () => nudgeShownTokens.clear(), noteCompressOutcomes, compressRetryCappedFor, clearCompressRetryTracking, liveContextLimit, configFor, reloadConfig, stateFor, save, acquireLock, overflowFor, overflowDrop, noteDeadCompress, clearDeadCompress, throttleFor, throttleDrop, noteTokenScale, dropTokenScale };
|
|
5340
|
+
}, clearNudgeTokenStamps: () => nudgeShownTokens.clear(), noteCompressOutcomes, compressRetryCappedFor, clearCompressRetryTracking, liveContextLimit, configFor, reasoningDropFor, reloadConfig, stateFor, save, acquireLock, overflowFor, overflowDrop, noteDeadCompress, clearDeadCompress, throttleFor, throttleDrop, noteTokenScale, dropTokenScale };
|
|
5257
5341
|
}
|
|
5258
5342
|
|
|
5259
5343
|
// node_modules/typebox/build/system/memory/memory.mjs
|
|
@@ -16749,7 +16833,7 @@ async function statusReport(runtime, ctx) {
|
|
|
16749
16833
|
const sentTokens = estimateTokens(coreMessages, coveredIds, imageTokens) + systemPromptTokens;
|
|
16750
16834
|
const viewSentTokens = adjustedTokenCount(runtime.core, coreMessages, state, config, sentTokens, imageTokens, systemPromptTokens);
|
|
16751
16835
|
const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount: anchorStale ? viewSentTokens : Math.max(viewSentTokens, realUsage?.tokens ?? 0) });
|
|
16752
|
-
const versionStr = "0.1.
|
|
16836
|
+
const versionStr = "0.1.62" ? `billion-context-pi@${"0.1.62"}` : void 0;
|
|
16753
16837
|
let text = buildStatusPanel({
|
|
16754
16838
|
version: versionStr,
|
|
16755
16839
|
tokenCount: sessionTokens,
|
|
@@ -17283,7 +17367,7 @@ async function autoInstallLatest(latest, extDirOverride) {
|
|
|
17283
17367
|
"--no-fund",
|
|
17284
17368
|
"--no-save"
|
|
17285
17369
|
];
|
|
17286
|
-
const prevVersion = (await readPackageJson(join11(extDir, "package.json")))?.version ?? "0.1.
|
|
17370
|
+
const prevVersion = (await readPackageJson(join11(extDir, "package.json")))?.version ?? "0.1.62";
|
|
17287
17371
|
const { code, stderr } = await runNpmImpl(installArgs(latest), { cwd: npmDir, timeout: 6e4 });
|
|
17288
17372
|
if (code !== 0) {
|
|
17289
17373
|
logWarn("update", {
|
|
@@ -17301,7 +17385,7 @@ async function autoInstallLatest(latest, extDirOverride) {
|
|
|
17301
17385
|
}
|
|
17302
17386
|
const verify = await verifyInstall(npmDir, latest);
|
|
17303
17387
|
if (!verify.ok) {
|
|
17304
|
-
const rollbackTo = SEMVER_RE.test(prevVersion) ? prevVersion : "0.1.
|
|
17388
|
+
const rollbackTo = SEMVER_RE.test(prevVersion) ? prevVersion : "0.1.62";
|
|
17305
17389
|
logWarn("update", { event: "auto-install-verify-failed", latest, reason: verify.reason, rollbackTo });
|
|
17306
17390
|
const rb = await runNpmImpl(installArgs(rollbackTo), { cwd: npmDir, timeout: 6e4 });
|
|
17307
17391
|
logInfo("update", { event: "rollback", from: latest, to: rollbackTo, ok: rb.code === 0 });
|
|
@@ -17376,7 +17460,7 @@ async function checkForUpdate(autoUpdate, notify) {
|
|
|
17376
17460
|
}
|
|
17377
17461
|
const latest = await fetchLatestVersion(tag);
|
|
17378
17462
|
if (!latest) return;
|
|
17379
|
-
const current = runtimeVersion ?? "0.1.
|
|
17463
|
+
const current = runtimeVersion ?? "0.1.62";
|
|
17380
17464
|
const hasUpdate = isVersionNewer(latest, current);
|
|
17381
17465
|
debug.event("update-check", {
|
|
17382
17466
|
current,
|
|
@@ -17554,7 +17638,7 @@ function wireSessionLifecycle(pi, runtime, standDownIfProxied) {
|
|
|
17554
17638
|
setDelegatePolicy(DEFAULT_DELEGATE_POLICY);
|
|
17555
17639
|
const sid = ctx.sessionManager.getSessionId();
|
|
17556
17640
|
const modelInfo = ctx.model;
|
|
17557
|
-
logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.
|
|
17641
|
+
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
17642
|
try {
|
|
17559
17643
|
await runtime.reloadConfig(ctx.cwd);
|
|
17560
17644
|
const delegateCfg = resolveDelegate(runtime.adapter);
|
|
@@ -17701,7 +17785,13 @@ function wireContextTransform(pi, runtime, standDownIfProxied) {
|
|
|
17701
17785
|
activeAfter: turn.state.blocks.filter((b2) => b2.active).length
|
|
17702
17786
|
});
|
|
17703
17787
|
const originalById = collectOriginals(entries);
|
|
17704
|
-
|
|
17788
|
+
let rebuilt = coreOutToAgentMessages(turn.messages, originalById);
|
|
17789
|
+
const reasoningDrop = runtime.reasoningDropFor(ctx);
|
|
17790
|
+
const droppedThinking = dropCompressReasoning(rebuilt, reasoningDrop);
|
|
17791
|
+
if (droppedThinking !== rebuilt) {
|
|
17792
|
+
debug.event("reasoning-drop", { sid, dropped: droppedThinking.length, drop: reasoningDrop.drop, threshold: reasoningDrop.threshold });
|
|
17793
|
+
}
|
|
17794
|
+
rebuilt = droppedThinking;
|
|
17705
17795
|
const debugOn2 = debug.enabled;
|
|
17706
17796
|
const turnKey = lastUserMessageId(entries) ?? sid;
|
|
17707
17797
|
const compressOutcomes = collectCompressOutcomes(entries, turnStartIndex(entries));
|