cleanMessage
A message as given (-m, a tool's message): line endings as \n, trailing spaces and blank lines at either end
taken off. Nothing left is no message.
export function cleanMessage(message: string | undefined): string | undefined { const lines = (message ?? "") .replace(/\r\n?/g, "\n") .split("\n") .map((l) => l.trimEnd()); while (lines.length && !lines[0]) lines.shift(); while (lines.length && !lines.at(-1)) lines.pop(); return lines.join("\n") || undefined; }