* 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)
| 1739 | * can Read the full file if needed. |
| 1740 | */ |
| 1741 | function truncateToTokens(content: string, maxTokens: number): string { |
| 1742 | if (roughTokenCountEstimation(content) <= maxTokens) { |
| 1743 | return content |
| 1744 | } |
| 1745 | const charBudget = maxTokens * 4 - SKILL_TRUNCATION_MARKER.length |
| 1746 | return content.slice(0, charBudget) + SKILL_TRUNCATION_MARKER |
| 1747 | } |
| 1748 | |
| 1749 | function shouldExcludeFromPostCompactRestore( |
| 1750 | filename: string, |
no test coverage detected