MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / estimateTokens

Method estimateTokens

src/agent/loop.ts:2659–2670  ·  view source on GitHub ↗
(messages: Message[])

Source from the content-addressed store, hash-verified

2657 // head + "[N chars spilled — full output: <path>]" + tail, so the model
2658 // keeps status lines and tail errors AND knows how to read the rest
2659 // (read_file with offset/limit). isError and metadata pass through
2660 // untouched. Runs BEFORE the read-only cache store so a cache hit can
2661 // never resurrect the full-size copy. Best-effort: a failed spill must
2662 // never eat the result.
2663 const spillMax = this.config.tools?.maxResultChars ?? 16_000;
2664 if (spillMax > 0 && typeof result.content === 'string' && result.content.length > spillMax) {
2665 try {
2666 const spill = await applySpillGuard(tc.function.name, sessionId, result.content, {
2667 maxResultChars: spillMax,
2668 });
2669 if (spill.spilled) {
2670 logger.info('Tool result spilled to disk', {
2671 tool: tc.function.name,
2672 chars: result.content.length,
2673 spillPath: spill.spillPath,

Callers 3

runMethod · 0.95
runCompactionMethod · 0.95
pruneMessagesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected