/ src / server / tools / bash / render.ts
render.ts
 1  export function renderBashToolOutputForChat(output: Record<string, unknown>): string {
 2    if (output.ok !== true) {
 3      const error =
 4        typeof output.error === 'string' ? output.error : 'bash failed'
 5      return `Bash tool failed: ${error}`
 6    }
 7  
 8    const command = typeof output.command === 'string' ? output.command : null
 9    const cwd = typeof output.cwd === 'string' ? output.cwd : null
10    const exitCode =
11      typeof output.exitCode === 'number' || output.exitCode === null
12        ? output.exitCode
13        : null
14    const timedOut = output.timedOut === true
15    const failureReason =
16      typeof output.failureReason === 'string' ? output.failureReason.trim() : ''
17    const stdout = typeof output.stdout === 'string' ? output.stdout : ''
18    const stderr = typeof output.stderr === 'string' ? output.stderr : ''
19    const stdoutTrimmed = stdout.trim()
20    const stderrTrimmed = stderr.trim()
21  
22    const lines: string[] = []
23    lines.push(`Bash tool result${command ? ` (\`${command}\`)` : ''}:`)
24    if (cwd) lines.push(`- cwd: ${cwd}`)
25    lines.push(`- exit code: ${exitCode ?? 'null'}`)
26    lines.push(`- timed out: ${timedOut ? 'yes' : 'no'}`)
27    if (failureReason) lines.push(`- reason: ${failureReason}`)
28    if (stdoutTrimmed) {
29      lines.push('- stdout:')
30      lines.push(stdoutTrimmed)
31    } else {
32      lines.push('- stdout: (empty)')
33    }
34    if (stderrTrimmed) {
35      lines.push('- stderr:')
36      lines.push(stderrTrimmed)
37    }
38    return lines.join('\n')
39  }