MCPcopy Create free account
hub / github.com/block/buzz / parseReadFileOutput

Function parseReadFileOutput

desktop/src/features/agents/ui/agentSessionFileRead.ts:95–117  ·  view source on GitHub ↗
(resultText: string, path: string)

Source from the content-addressed store, hash-verified

93}
94
95function parseReadFileOutput(resultText: string, path: string) {
96 const rawLines = trimTrailingEmptyLines(resultText.split(/\r?\n/));
97 const firstLine = rawLines[0] ?? "";
98 const remainingLines = rawLines.slice(1);
99 const hasRangeHeader =
100 firstLine.startsWith(path) && /\s\(lines \d+-\d+ of \d+\)$/.test(firstLine);
101 const contentLines = hasRangeHeader ? remainingLines : rawLines;
102 const lines =
103 contentLines.length > 0
104 ? contentLines.map((line) => ({
105 kind: isReadFileMetaLine(line)
106 ? ("meta" as const)
107 : ("context" as const),
108 text: line,
109 }))
110 : [{ kind: "meta" as const, text: "No file content returned." }];
111
112 return {
113 footerText: hasRangeHeader ? firstLine : path,
114 footerTitle: hasRangeHeader ? `${path}\n${firstLine}` : path,
115 lines,
116 };
117}
118
119function getResultText(result: string): string {
120 const parsed = parseToolResultValue(result);

Callers 1

buildFileReadContentFunction · 0.85

Calls 2

trimTrailingEmptyLinesFunction · 0.85
isReadFileMetaLineFunction · 0.85

Tested by

no test coverage detected