MCPcopy Create free account
hub / github.com/cloudflare/computer / processLine

Function processLine

packages/computer/src/tools/fs/read.ts:81–107  ·  view source on GitHub ↗
(line: string)

Source from the content-addressed store, hash-verified

79 let firstLineOverflow = false;
80
81 const processLine = (line: string): boolean => {
82 // Returns true to keep going, false to stop the outer pump.
83 if (currentLine < startLine) {
84 currentLine++;
85 return true;
86 }
87 // We're at or past `startLine` — try to emit.
88 const lineBytes = utf8ByteLength(line);
89 if (collected.length === 0 && lineBytes > maxBytes) {
90 firstLineOverflow = true;
91 return false;
92 }
93 // Stop before emitting if this line would push us over either cap.
94 if (collected.length >= lineCap) {
95 truncatedByBudget = true;
96 return false;
97 }
98 if (collectedBytes + lineBytes + (collected.length > 0 ? 1 : 0) > maxBytes) {
99 truncatedByBudget = true;
100 return false;
101 }
102 if (firstEmittedLine === null) firstEmittedLine = currentLine;
103 collected.push(line);
104 collectedBytes += lineBytes + (collected.length > 1 ? 1 : 0);
105 currentLine++;
106 return true;
107 };
108
109 let keepGoing = true;
110 for await (const chunk of store.readChunks(path)) {

Callers 1

createReadToolFunction · 0.85

Calls 2

utf8ByteLengthFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected