(content: string)
| 131 | } |
| 132 | |
| 133 | export function formatOutput(content: string): { |
| 134 | totalLines: number |
| 135 | truncatedContent: string |
| 136 | isImage?: boolean |
| 137 | } { |
| 138 | const isImage = isImageOutput(content) |
| 139 | if (isImage) { |
| 140 | return { |
| 141 | totalLines: 1, |
| 142 | truncatedContent: content, |
| 143 | isImage, |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | const maxOutputLength = getMaxOutputLength() |
| 148 | if (content.length <= maxOutputLength) { |
| 149 | return { |
| 150 | totalLines: countCharInString(content, '\n') + 1, |
| 151 | truncatedContent: content, |
| 152 | isImage, |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | const truncatedPart = content.slice(0, maxOutputLength) |
| 157 | const remainingLines = countCharInString(content, '\n', maxOutputLength) + 1 |
| 158 | const truncated = `${truncatedPart}\n\n... [${remainingLines} lines truncated] ...` |
| 159 | |
| 160 | return { |
| 161 | totalLines: countCharInString(content, '\n') + 1, |
| 162 | truncatedContent: truncated, |
| 163 | isImage, |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | export const stdErrAppendShellResetMessage = (stderr: string): string => |
| 168 | `${stderr.trim()}\nShell cwd was reset to ${getOriginalCwd()}` |
no test coverage detected