* Truncate content to roughly maxTokens, keeping the head. roughTokenCountEstimation * uses ~4 chars/token (its default bytesPerToken), so char budget = maxTokens * 4 * minus the marker so the result stays within budget. Marker tells the model it * can Read the full file if needed.
(content: string, maxTokens: number)
| 1664 | * can Read the full file if needed. |
| 1665 | */ |
| 1666 | function truncateToTokens(content: string, maxTokens: number): string { |
| 1667 | if (roughTokenCountEstimation(content) <= maxTokens) { |
| 1668 | return content |
| 1669 | } |
| 1670 | const charBudget = maxTokens * 4 - SKILL_TRUNCATION_MARKER.length |
| 1671 | return content.slice(0, charBudget) + SKILL_TRUNCATION_MARKER |
| 1672 | } |
| 1673 | |
| 1674 | function shouldExcludeFromPostCompactRestore( |
| 1675 | filename: string, |
no test coverage detected