"""HTML views for MCP runtime health (#430).""" from __future__ import annotations import html from webui.runtime_health import FileHash, RuntimeSnapshot def _hash_rows(items: tuple[FileHash, ...]) -> str: if not items: return "

No hashes available.

" rows = [] for item in items: digest = item.sha256 or item.error or "unavailable" rows.append( "" f"{html.escape(item.label)}" f"{html.escape(item.path)}" f"{html.escape(digest[:16] if item.sha256 else digest)}" "" ) return ( "" "" "" f"{''.join(rows)}
ArtifactPathSHA-256
" ) def render_runtime_page(snapshot: RuntimeSnapshot) -> str: error_block = "" if snapshot.fetch_error: error_block = ( '

Runtime snapshot incomplete: ' f"{html.escape(snapshot.fetch_error)}

" ) identity = snapshot.authenticated_username or "unresolved" if snapshot.identity_error: identity = f"unresolved ({snapshot.identity_error})" stale_block = "" if snapshot.stale_runtime_warning: stale_block = ( '

Stale runtime warning: ' f"{html.escape(snapshot.stale_runtime_warning)}

" ) shell = snapshot.shell_health or {} shell_summary = ( f"shell_use_allowed={shell.get('shell_use_allowed')} · " f"failures={shell.get('consecutive_spawn_failures')} · " f"hard_stopped={shell.get('hard_stopped')}" ) return ( "

Runtime health

" f"

Project {html.escape(snapshot.project_id)} · " f"host {html.escape(snapshot.host)} · " f"repo root {html.escape(snapshot.repo_root)}

" f"{error_block}" f"{stale_block}" "

Active profile

" "" f"" f"" f"" f"" f"" "
Profile{html.escape(snapshot.profile_name)}
Role kind{html.escape(snapshot.role_kind)}
Identity{html.escape(identity)}
Config model{html.escape(snapshot.config_model)}
Profile mode{html.escape(snapshot.profile_mode)} " f"({html.escape(snapshot.profile_source)})
" "

Server code sync

" "" f"" f"" f"" f"" "
Local HEAD{html.escape(snapshot.repo_sha or 'unknown')}
Remote {html.escape(snapshot.remote)}/{html.escape('master')}{html.escape(snapshot.remote_master_sha or 'unknown')}
Commits behind{snapshot.commits_behind_master if snapshot.commits_behind_master is not None else 'unknown'}
" "

Shell health

" f"

{html.escape(shell_summary)}

" f"

{html.escape(str(shell.get('safe_next_action') or ''))}

" "

Workflow hashes

" f"{_hash_rows(snapshot.workflow_hashes)}" "

Schema hashes

" f"{_hash_rows(snapshot.schema_hashes)}" "

Restart / reload

" "

MVP is read-only — restart MCP servers from your IDE/operator " "workflow. Related issue: #420. Guidance: " f"{html.escape(snapshot.restart_guidance)}

" "

This page does not expose tokens or perform MCP restarts.

" )