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)/; /** A link under a message: never the bare «/», never Gitea for a product manager. */ export function messageLink(url: string | null, superadmin: boolean, gitea: string): string | null { if (!url || url === "/" || url === "#") return null; if (!superadmin && gitea && url.startsWith(gitea)) return null; return url; } /** PEP-207: the factory's «задерживается на нашей стороне» — the status line of the chat with the analyst, not a message. */ export const STUCK_NOTICE = /задерживается на нашей стороне/i;