"""HTML views for the prompt library (#428).""" from __future__ import annotations import html from webui.layout import render_page from webui.prompt_library import PromptEntry, load_prompt_library def _escape(text: str) -> str: return html.escape(text, quote=True) def _render_prompt_card(entry: PromptEntry) -> str: hash_short = ( f"{_escape(entry.workflow_hash[:12])}" if entry.workflow_hash else "n/a" ) task_mode = ( f"{_escape(entry.task_mode)}" if entry.task_mode else "n/a" ) note = ( f'

{_escape(entry.source_note)}

' if entry.source_note else "" ) prompt_id = f"prompt-{entry.slug}" return ( f'
' f"

{_escape(entry.label)}

" f'

Workflow: {_escape(entry.workflow_path)} · ' f"task_mode: {task_mode} · sha256: {hash_short}

" f'
{_escape(entry.prompt_text)}
' f'" f"{note}" "
" ) PROMPT_PAGE_SCRIPT = """ """ def render_prompts_page() -> str: entries = load_prompt_library() cards = "".join(_render_prompt_card(entry) for entry in entries) body = ( "

Prompt library

" "

Short copy/paste task prompts derived from canonical workflows. " "Full policy remains in the cited workflow files — not duplicated here.

" f"{cards}" "

JSON API

" f"{PROMPT_PAGE_SCRIPT}" ) return render_page(title="Prompts", body_html=body) def render_prompt_detail(entry: PromptEntry) -> str: body = ( f"

← All prompts

" f"{_render_prompt_card(entry)}" f"{PROMPT_PAGE_SCRIPT}" ) return render_page(title=entry.label, body_html=body)