"""HTML views for branches/ worktree hygiene dashboard (#432).""" from __future__ import annotations import html from webui.layout import render_page from webui.worktree_scanner import HygieneSnapshot, WorktreeEntry def _escape(text: str) -> str: return html.escape(text, quote=True) def _badge(classification: str) -> str: return ( f'' f"{_escape(classification)}" ) def _entry_row(entry: WorktreeEntry) -> str: branch = entry.branch or "โ€”" head = entry.head_sha[:12] if entry.head_sha else "โ€”" dirty = ( f"{entry.dirty_tracked} tracked" + (" + untracked" if entry.dirty_untracked else "") if entry.dirty_tracked or entry.dirty_untracked else "clean" ) return ( "" f"{_escape(entry.rel_path)}" f"{_badge(entry.classification)}" f"{_escape(branch)}" f"{_escape(head)}" f"{_escape(dirty)}" f"{'yes' if entry.detached else 'no'}" f"{_escape(entry.notes)}" "" ) WORKTREE_PAGE_SCRIPT = """ """ WORKTREE_PAGE_STYLES = """ """ def render_worktrees_page(snapshot: HygieneSnapshot) -> str: error_block = "" if snapshot.scan_error: error_block = ( '

Partial scan: ' f"{_escape(snapshot.scan_error)}

" ) anomaly_block = "" if snapshot.anomalies: items = "".join(f"
  • {_escape(text)}
  • " for text in snapshot.anomalies) anomaly_block = ( '

    Missing preserved worktree anomalies

    ' f"
    " ) if snapshot.entries: rows = "".join(_entry_row(entry) for entry in snapshot.entries) table = ( "" "" "" "" "" f"{rows}
    PathClassBranchHEADDirtyDetachedNotes
    " ) else: table = "

    No directories under branches/.

    " body = ( "

    Worktree hygiene

    " "

    Read-only scan of local branches/ worktrees. " "No deletion actions โ€” copy the canonical cleanup prompt when merge is confirmed.

    " f"{error_block}" f"{anomaly_block}" f"

    Repo root: {_escape(snapshot.repo_root)} ยท " f"entries: {len(snapshot.entries)}

    " f"{table}" "

    Canonical cleanup prompt

    " f'
    {_escape(snapshot.cleanup_prompt)}
    ' '' "

    JSON API

    " f"{WORKTREE_PAGE_STYLES}" f"{WORKTREE_PAGE_SCRIPT}" ) return render_page(title="Worktrees", body_html=body)