import { keyHint, type MessageRenderer, type Theme, } from "@earendil-works/pi-coding-agent"; import { stripTerminalSequences, Text } from "@earendil-works/pi-tui"; import type { PromptDetails } from "./controller.ts"; import { ICON } from "./icons.ts"; type CustomMessage = Parameters>[0]; function bodyText(content: CustomMessage["content"]): string { return typeof content === "string" ? content : content .flatMap((part) => (part.type === "text" ? [part.text] : [])) .join("\n"); } /** Compact loop prompt row; the full prompt needs the native tool expansion key. */ export function renderLoopPrompt( message: CustomMessage, { expanded, keyHint: hostKeyHint, }: { expanded: boolean; keyHint?: typeof keyHint; }, theme: Theme, ): Text { const summary = message.details?.stub ? message.details.stub.replace(/ Superseded by a later loop prompt\.$/u, "") : "Loop prompt"; const head = theme.fg( "customMessageLabel", `${ICON.loop} ${stripTerminalSequences(summary)}`, ); return new Text( expanded ? `${head}\n${theme.fg("customMessageText", stripTerminalSequences(bodyText(message.content)))}` : `${head} ${(hostKeyHint ?? keyHint)("app.tools.expand", "to expand")}`, 0, 0, ); }