diff --git a/package-lock.json b/package-lock.json index dc8ae88..579d082 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "billion-context-pi", - "version": "0.1.62", + "version": "0.1.63", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "billion-context-pi", - "version": "0.1.62", + "version": "0.1.63", "license": "MIT", "devDependencies": { "@earendil-works/pi-coding-agent": "0.83.0", diff --git a/package.json b/package.json index 5e67d2d..b084bc2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "billion-context-pi", - "version": "0.1.62", + "version": "0.1.63", "description": "One billion, not one million. Model-driven context management for the Pi coding agent.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 875e278..e6c4d5b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,7 +19,7 @@ import { makeStatusTool } from "./status-tool.js"; import { makeDelegateTool, makeDelegateWaitTool, makeDelegateCancelTool, runningRunsSnapshot, resetDelegateUsage, setDelegateDisplayUsage, setDelegatePolicy, setDelegateDefaults, setDelegateNotifyIfRead, markDelegateResultRead, markDelegateRunReadByCommand } from "./delegate-tool.js"; import { makeCommands } from "./commands.js"; import { coreOutToAgentMessages, extractText } from "./messages.js"; -import { dropCompressReasoning } from "./reasoning-drop.js"; +import { countThinkingChars, dropCompressReasoning } from "./reasoning-drop.js"; import { buildAcpSystemPrompt, ACP_DELEGATE_PROMPT } from "./system-prompt.js"; import { delegateStatusWidget } from "./fleet-widget.js"; import { openFleetInspector } from "./fleet-inspector.js"; @@ -412,7 +412,8 @@ function wireContextTransform(pi: ExtensionAPI, runtime: AcpRuntime, standDownIf const reasoningDrop = runtime.reasoningDropFor(ctx); const droppedThinking = dropCompressReasoning(rebuilt, reasoningDrop); if (droppedThinking !== rebuilt) { - debug.event("reasoning-drop", { sid, dropped: droppedThinking.length, drop: reasoningDrop.drop, threshold: reasoningDrop.threshold }); + const droppedChars = countThinkingChars(rebuilt) - countThinkingChars(droppedThinking); + debug.event("reasoning-drop", { sid, droppedChars, drop: reasoningDrop.drop, threshold: reasoningDrop.threshold }); } rebuilt = droppedThinking; const debugOn = debug.enabled; diff --git a/src/reasoning-drop.ts b/src/reasoning-drop.ts index 26b2595..d698c4a 100644 --- a/src/reasoning-drop.ts +++ b/src/reasoning-drop.ts @@ -84,6 +84,10 @@ function reasoningLength(content: unknown): number { return content.reduce((n, p) => (isThinking(p) ? n + p.thinking.length : n), 0); } +export function countThinkingChars(messages: AgentMessage[]): number { + return messages.reduce((n, m) => n + reasoningLength((m as { content?: unknown }).content), 0); +} + /** Request-time pass aligned with opencode-acp #377: remove `thinking` parts * from a message only when ALL gates hold — * 1. closed round [#348]: EVERY `compress` toolCall in the message has its