diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 05afc0e..c59411c 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -206,9 +206,18 @@ const pruneToolInputs = ( continue } - if (part.state.input?.content !== undefined) { + // Write tool has content field, edit tool has oldString/newString fields + if (part.tool === 'write' && part.state.input?.content !== undefined) { part.state.input.content = PRUNED_TOOL_INPUT_REPLACEMENT } + if (part.tool === 'edit') { + if (part.state.input?.oldString !== undefined) { + part.state.input.oldString = PRUNED_TOOL_INPUT_REPLACEMENT + } + if (part.state.input?.newString !== undefined) { + part.state.input.newString = PRUNED_TOOL_INPUT_REPLACEMENT + } + } } } } diff --git a/lib/strategies/utils.ts b/lib/strategies/utils.ts index ca610be..7a675fb 100644 --- a/lib/strategies/utils.ts +++ b/lib/strategies/utils.ts @@ -55,7 +55,7 @@ export const calculateTokensSaved = ( } // For write and edit tools, count input content as that is all we prune for these tools // (input is present in both completed and error states) - if (part.tool === "write" || part.tool === "edit") { + if (part.tool === "write") { const inputContent = part.state.input?.content const content = typeof inputContent === 'string' ? inputContent @@ -63,6 +63,17 @@ export const calculateTokensSaved = ( contents.push(content) continue } + if (part.tool === "edit") { + const oldString = part.state.input?.oldString + const newString = part.state.input?.newString + if (typeof oldString === 'string') { + contents.push(oldString) + } + if (typeof newString === 'string') { + contents.push(newString) + } + continue + } // For other tools, count output or error based on status if (part.state.status === "completed") { const content = typeof part.state.output === 'string'