import { userText } from "@peppa/core"; /** PEP-207: what a person reads of the factory's text — no terminal output, paths or service blocks. */ export function cleanText(text: string, superadmin: boolean, gitea = ""): string { if (superadmin) return text; // The agent CLI's screen («⏺ Calling…», «⎿ …», rules) starts where the person's text ends. const lines = text.split("\n"); const cut = lines.findIndex((l) => TERMINAL_LINE.test(l)); let out = userText(cut >= 0 ? lines.slice(0, cut).join("\n") : text) || lines[0]!; if (gitea) out = out.split(gitea).length > 1 ? out.replace(new RegExp(`${gitea.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\S*`, "g"), "").replace(/[ \t]+\n/g, "\n").trim() : out; return out; } const TERMINAL_LINE = /^\s*(?:[⏺⎿●│└├╭╰─━]|\$ |> |✻|Calling\b|Running\b)/;