17 lines
502 B
TypeScript
17 lines
502 B
TypeScript
export function normalizeCursorStreamLine(rawLine: string): {
|
|
stream: "stdout" | "stderr" | null;
|
|
line: string;
|
|
} {
|
|
const trimmed = rawLine.trim();
|
|
if (!trimmed) return { stream: null, line: "" };
|
|
|
|
const prefixed = trimmed.match(/^(stdout|stderr)\s*[:=]?\s*([\[{].*)$/i);
|
|
if (!prefixed) {
|
|
return { stream: null, line: trimmed };
|
|
}
|
|
|
|
const stream = prefixed[1]?.toLowerCase() === "stderr" ? "stderr" : "stdout";
|
|
const line = (prefixed[2] ?? "").trim();
|
|
return { stream, line };
|
|
}
|