MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / processBuffer

Function processBuffer

src/integrations/misc/line-counter.ts:98–120  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96 })
97
98 const processBuffer = async () => {
99 if (lineBuffer.length === 0) return
100
101 const bufferText = lineBuffer.join("\n")
102 lineBuffer = [] // Clear buffer before processing
103
104 try {
105 const contentBlocks: Anthropic.Messages.ContentBlockParam[] = [{ type: "text", text: bufferText }]
106 const chunkTokens = await countTokens(contentBlocks)
107 tokenEstimate += chunkTokens
108 } catch (error) {
109 // On tokenizer error, use conservative estimate: 2 char ≈ 1 token
110 tokenEstimate += Math.ceil(bufferText.length / 2)
111 }
112
113 // Check if we've exceeded budget
114 if (budgetTokens !== undefined && tokenEstimate > budgetTokens) {
115 complete = false
116 shouldClose = true
117 rl.close()
118 readStream.destroy()
119 }
120 }
121
122 rl.on("line", (line) => {
123 lineCount++

Callers 1

countFileLinesAndTokensFunction · 0.70

Calls 2

countTokensFunction · 0.90
closeMethod · 0.65

Tested by

no test coverage detected