Fix clarify icon alignment and spurious error-red on non-zero exit

- clarify-tool: top-align the help icon (items-start + mt-px) so it sits
  beside the first line of a multi-line question instead of floating
  centered against the whole block.
- tool-fallback: a non-zero exit code alone no longer paints the whole
  terminal/execute_code card red. grep no-match, diff differences, and
  piped commands routinely exit non-zero while producing useful output;
  only flag an error when the command produced no output. Explicit error
  signals (error field, success=false, status=error, isError) still go red.
- Add regression tests covering the exit-code -> status matrix.
This commit is contained in:
Brooklyn Nicholson
2026-06-06 09:23:50 -05:00
parent 40386f33ec
commit 6bbc5eefa0
3 changed files with 45 additions and 3 deletions
@@ -742,9 +742,20 @@ function toolErrorText(part: ToolPart, result: Record<string, unknown>): string
return firstStringField(result, ['message', 'reason', 'detail']) || `Tool returned status "${result.status}".`
}
// A non-zero exit code alone is a weak failure signal: grep returns 1 on
// no-match, diff returns 1 on differences, piped commands surface the last
// stage's code, etc. — all routinely produce useful output and aren't
// failures. Only treat it as an error when the command produced no real
// output to show; otherwise render the output normally (not red).
const exit = numberValue(result.exit_code)
return exit !== null && exit !== 0 ? `Command failed with exit code ${exit}.` : ''
if (exit !== null && exit !== 0) {
const hasOutput = Boolean(firstStringField(result, ['output', 'stdout', 'stderr'])?.trim())
return hasOutput ? '' : `Command failed with exit code ${exit}.`
}
return ''
}
function toolStatus(part: ToolPart, resultRecord: Record<string, unknown>): ToolStatus {