( data: ContextData, suggestions: ContextSuggestion[], )
| 149 | } |
| 150 | |
| 151 | function checkReadResultBloat( |
| 152 | data: ContextData, |
| 153 | suggestions: ContextSuggestion[], |
| 154 | ): void { |
| 155 | if (!data.messageBreakdown) return |
| 156 | |
| 157 | const callsByType = data.messageBreakdown.toolCallsByType |
| 158 | const readTool = callsByType.find(t => t.name === FILE_READ_TOOL_NAME) |
| 159 | if (!readTool) return |
| 160 | |
| 161 | const totalReadTokens = readTool.callTokens + readTool.resultTokens |
| 162 | const totalReadPercent = (totalReadTokens / data.rawMaxTokens) * 100 |
| 163 | const readPercent = (readTool.resultTokens / data.rawMaxTokens) * 100 |
| 164 | |
| 165 | // Skip if already covered by checkLargeToolResults (>= 15% band) |
| 166 | if ( |
| 167 | totalReadPercent >= LARGE_TOOL_RESULT_PERCENT && |
| 168 | totalReadTokens >= LARGE_TOOL_RESULT_TOKENS |
| 169 | ) { |
| 170 | return |
| 171 | } |
| 172 | |
| 173 | if ( |
| 174 | readPercent >= READ_BLOAT_PERCENT && |
| 175 | readTool.resultTokens >= LARGE_TOOL_RESULT_TOKENS |
| 176 | ) { |
| 177 | suggestions.push({ |
| 178 | severity: 'info', |
| 179 | title: `File reads using ${formatTokens(readTool.resultTokens)} tokens (${readPercent.toFixed(0)}%)`, |
| 180 | detail: |
| 181 | 'If you are re-reading files, consider referencing earlier reads. Use offset/limit for large files.', |
| 182 | savingsTokens: Math.floor(readTool.resultTokens * 0.3), |
| 183 | }) |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | function checkMemoryBloat( |
| 188 | data: ContextData, |
no test coverage detected