(resultText: string, path: string)
| 93 | } |
| 94 | |
| 95 | function 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 | |
| 119 | function getResultText(result: string): string { |
| 120 | const parsed = parseToolResultValue(result); |
no test coverage detected