MCPcopy Index your code
hub / github.com/codeaashu/claude-code / formatOutput

Function formatOutput

src/tools/BashTool/utils.ts:133–165  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

131}
132
133export 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
167export const stdErrAppendShellResetMessage = (stderr: string): string =>
168 `${stderr.trim()}\nShell cwd was reset to ${getOriginalCwd()}`

Callers 1

processOutputTextFunction · 0.85

Calls 3

isImageOutputFunction · 0.85
getMaxOutputLengthFunction · 0.85
countCharInStringFunction · 0.85

Tested by

no test coverage detected