MCPcopy Create free account
hub / github.com/Noumena-Network/code / truncateToTokens

Function truncateToTokens

src/services/compact/compact.ts:1741–1747  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

1739 * can Read the full file if needed.
1740 */
1741function 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
1749function shouldExcludeFromPostCompactRestore(
1750 filename: string,

Callers 1

Calls 1

Tested by

no test coverage detected