generated from coulomb/repo-seed
1380 lines
49 KiB
Python
1380 lines
49 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import asdict
|
|
from html import escape
|
|
|
|
from fastapi import APIRouter, Depends, Form
|
|
from fastapi.responses import HTMLResponse, RedirectResponse
|
|
|
|
from repo_registry.core.service import RegistryService
|
|
from repo_registry.web_api.app import get_service
|
|
|
|
|
|
router = APIRouter(include_in_schema=False)
|
|
|
|
|
|
def page(title: str, body: str) -> HTMLResponse:
|
|
return HTMLResponse(
|
|
f"""
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>{escape(title)} · Repository Ability Registry</title>
|
|
<style>
|
|
:root {{
|
|
color-scheme: light;
|
|
--bg: #f7f8fa;
|
|
--panel: #ffffff;
|
|
--text: #1f2933;
|
|
--muted: #637381;
|
|
--line: #d9dee7;
|
|
--accent: #0f766e;
|
|
--accent-dark: #115e59;
|
|
--warn: #9a3412;
|
|
}}
|
|
* {{ box-sizing: border-box; }}
|
|
body {{
|
|
margin: 0;
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
}}
|
|
header {{
|
|
background: #17212b;
|
|
color: #fff;
|
|
padding: 14px 28px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}}
|
|
header a {{ color: #e6fffb; text-decoration: none; }}
|
|
main {{ max-width: 1180px; margin: 0 auto; padding: 24px; }}
|
|
h1 {{ font-size: 24px; margin: 0 0 18px; }}
|
|
h2 {{ font-size: 18px; margin: 28px 0 10px; }}
|
|
h3 {{ font-size: 15px; margin: 16px 0 6px; }}
|
|
p {{ margin: 0 0 10px; }}
|
|
a {{ color: var(--accent-dark); }}
|
|
.grid {{ display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }}
|
|
.panel {{
|
|
background: var(--panel);
|
|
border: 1px solid var(--line);
|
|
border-radius: 8px;
|
|
padding: 16px;
|
|
}}
|
|
.stack {{ display: grid; gap: 12px; }}
|
|
.muted {{ color: var(--muted); }}
|
|
.pill {{
|
|
display: inline-flex;
|
|
align-items: center;
|
|
min-height: 24px;
|
|
padding: 2px 8px;
|
|
border: 1px solid var(--line);
|
|
border-radius: 999px;
|
|
color: var(--muted);
|
|
background: #fbfcfd;
|
|
font-size: 12px;
|
|
}}
|
|
table {{ width: 100%; border-collapse: collapse; background: var(--panel); }}
|
|
th, td {{ text-align: left; border-bottom: 1px solid var(--line); padding: 10px 8px; vertical-align: top; }}
|
|
th {{ color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }}
|
|
input, textarea {{
|
|
width: 100%;
|
|
border: 1px solid var(--line);
|
|
border-radius: 6px;
|
|
padding: 9px 10px;
|
|
font: inherit;
|
|
}}
|
|
label {{ display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 600; }}
|
|
button, .button {{
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
min-height: 34px;
|
|
padding: 7px 12px;
|
|
border: 1px solid var(--accent);
|
|
border-radius: 6px;
|
|
background: var(--accent);
|
|
color: white;
|
|
font: inherit;
|
|
font-weight: 650;
|
|
text-decoration: none;
|
|
cursor: pointer;
|
|
}}
|
|
.button.secondary, button.secondary {{
|
|
color: var(--accent-dark);
|
|
background: white;
|
|
}}
|
|
.tree ul {{ margin: 8px 0 0 20px; padding: 0; }}
|
|
.tree li {{ margin: 6px 0; }}
|
|
.source {{ color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }}
|
|
.actions {{ display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }}
|
|
@media (max-width: 780px) {{
|
|
header {{ padding: 12px 16px; }}
|
|
main {{ padding: 16px; }}
|
|
.grid {{ grid-template-columns: 1fr; }}
|
|
table, tbody, tr, td {{ display: block; width: 100%; }}
|
|
thead {{ display: none; }}
|
|
td {{ border-bottom: 0; padding: 6px 0; }}
|
|
tr {{ border-bottom: 1px solid var(--line); padding: 10px 0; display: block; }}
|
|
}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<a href="/ui"><strong>Repository Ability Registry</strong></a>
|
|
<nav class="actions">
|
|
<a href="/ui/search">Search</a>
|
|
<a href="/docs">API Docs</a>
|
|
</nav>
|
|
</header>
|
|
<main>{body}</main>
|
|
</body>
|
|
</html>
|
|
"""
|
|
)
|
|
|
|
|
|
@router.get("/ui")
|
|
def repository_index(service: RegistryService = Depends(get_service)) -> HTMLResponse:
|
|
repositories = service.list_repositories()
|
|
rows = "\n".join(
|
|
f"""
|
|
<tr>
|
|
<td><a href="/ui/repos/{repo.id}">{escape(repo.name)}</a></td>
|
|
<td><span class="pill">{escape(repo.status)}</span></td>
|
|
<td class="source">{escape(repo.branch)}</td>
|
|
<td class="source">{escape(repo.url)}</td>
|
|
</tr>
|
|
"""
|
|
for repo in repositories
|
|
)
|
|
body = f"""
|
|
<h1>Repositories</h1>
|
|
<div class="grid">
|
|
<section class="panel">
|
|
<h2>Register Repository</h2>
|
|
<form class="stack" method="post" action="/ui/repos">
|
|
<label>Git URL or local path <input name="url" required></label>
|
|
<label>Branch <input name="branch" value="main"></label>
|
|
<button type="submit">Register</button>
|
|
</form>
|
|
</section>
|
|
<section class="panel">
|
|
<h2>Registry</h2>
|
|
<table>
|
|
<thead><tr><th>Name</th><th>Status</th><th>Branch</th><th>Source</th></tr></thead>
|
|
<tbody>{rows or '<tr><td colspan="4" class="muted">No repositories yet.</td></tr>'}</tbody>
|
|
</table>
|
|
</section>
|
|
</div>
|
|
"""
|
|
return page("Repositories", body)
|
|
|
|
|
|
@router.get("/ui/search")
|
|
def search_page(
|
|
q: str = "",
|
|
status: str = "",
|
|
language: str = "",
|
|
framework: str = "",
|
|
ability: str = "",
|
|
capability: str = "",
|
|
service: RegistryService = Depends(get_service),
|
|
) -> HTMLResponse:
|
|
results = (
|
|
service.search(
|
|
q,
|
|
status=status or None,
|
|
language=language or None,
|
|
framework=framework or None,
|
|
ability=ability or None,
|
|
capability=capability or None,
|
|
)
|
|
if q.strip()
|
|
else []
|
|
)
|
|
rows = "\n".join(
|
|
f"""
|
|
<tr>
|
|
<td><a href="{search_result_href(asdict(result))}">{escape(result.repository_name)}</a></td>
|
|
<td><span class="pill">{escape(result.match_type)}</span></td>
|
|
<td>
|
|
<strong>{escape(result.match_name)}</strong>
|
|
{render_search_context(asdict(result))}
|
|
</td>
|
|
<td>{escape(result.matched_field)}</td>
|
|
<td>{result.confidence:.2f}</td>
|
|
</tr>
|
|
"""
|
|
for result in results
|
|
)
|
|
empty = (
|
|
'<tr><td colspan="4" class="muted">No matches.</td></tr>'
|
|
if q.strip()
|
|
else '<tr><td colspan="4" class="muted">Enter a need, capability, or repository name.</td></tr>'
|
|
)
|
|
body = f"""
|
|
<div class="actions">
|
|
<h1 style="margin-right:auto">Search</h1>
|
|
<a class="button secondary" href="/ui">Repositories</a>
|
|
</div>
|
|
<section class="panel">
|
|
<form class="stack" method="get" action="/ui/search">
|
|
<input name="q" value="{escape(q)}" placeholder="Search approved registry entries">
|
|
<div class="grid">
|
|
<label>Status <input name="status" value="{escape(status)}" placeholder="indexed"></label>
|
|
<label>Language <input name="language" value="{escape(language)}" placeholder="Python"></label>
|
|
<label>Framework <input name="framework" value="{escape(framework)}" placeholder="FastAPI"></label>
|
|
<label>Ability <input name="ability" value="{escape(ability)}" placeholder="Email Routing"></label>
|
|
<label>Capability <input name="capability" value="{escape(capability)}" placeholder="Classification"></label>
|
|
</div>
|
|
<div class="actions">
|
|
<button type="submit">Search</button>
|
|
<a class="button secondary" href="/ui/search">Clear</a>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
<section class="panel" style="margin-top:18px">
|
|
<table>
|
|
<thead><tr><th>Repository</th><th>Match</th><th>Name</th><th>Field</th><th>Confidence</th></tr></thead>
|
|
<tbody>{rows or empty}</tbody>
|
|
</table>
|
|
</section>
|
|
"""
|
|
return page("Search", body)
|
|
|
|
|
|
@router.post("/ui/repos")
|
|
def create_repository_from_form(
|
|
url: str = Form(...),
|
|
branch: str = Form("main"),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
repository = service.register_repository(
|
|
url=url,
|
|
branch=branch or "main",
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository.id}", status_code=303)
|
|
|
|
|
|
@router.get("/ui/repos/{repository_id}")
|
|
def repository_detail(
|
|
repository_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> HTMLResponse:
|
|
repository = service.get_repository(repository_id)
|
|
runs = service.list_analysis_runs(repository_id)
|
|
ability_map = service.ability_map(repository_id)
|
|
decisions = service.list_review_decisions(repository_id)
|
|
facts = service.list_observed_facts(repository_id)
|
|
languages = sorted({fact.name for fact in facts if fact.kind == "language"})
|
|
frameworks = sorted({fact.name for fact in facts if fact.kind == "framework"})
|
|
run_rows = "\n".join(
|
|
f"""
|
|
<tr>
|
|
<td><a href="/ui/repos/{repository_id}/analysis-runs/{run.id}">#{run.id}</a></td>
|
|
<td><span class="pill">{escape(run.status)}</span></td>
|
|
<td class="source">{escape(run.started_at)}</td>
|
|
<td>{escape(run.error_message or '')}</td>
|
|
</tr>
|
|
"""
|
|
for run in runs
|
|
)
|
|
body = f"""
|
|
<div class="actions">
|
|
<h1 style="margin-right:auto">{escape(repository.name)}</h1>
|
|
<a class="button secondary" href="/ui">Back</a>
|
|
</div>
|
|
<p class="muted">{escape(repository.description or '')}</p>
|
|
<p><span class="pill">{escape(repository.status)}</span> <span class="source">{escape(repository.url)}</span></p>
|
|
{render_repository_facts(languages, frameworks)}
|
|
<div class="grid">
|
|
<section class="panel">
|
|
<h2>Repository Metadata</h2>
|
|
<form class="stack" method="post" action="/ui/repos/{repository_id}/edit">
|
|
<label>Name <input name="name" value="{escape(repository.name)}" required></label>
|
|
<label>Description <textarea name="description" rows="2">{escape(repository.description or '')}</textarea></label>
|
|
<label>Branch <input name="branch" value="{escape(repository.branch)}" required></label>
|
|
<button class="secondary" type="submit">Save Repository</button>
|
|
</form>
|
|
<h2>Run Analysis</h2>
|
|
<form class="stack" method="post" action="/ui/repos/{repository_id}/analysis-runs">
|
|
<label>Override source path <input name="source_path" placeholder="Optional local path"></label>
|
|
<button type="submit">Analyze</button>
|
|
</form>
|
|
<h2>Analysis Runs</h2>
|
|
<table>
|
|
<thead><tr><th>Run</th><th>Status</th><th>Started</th><th>Error</th></tr></thead>
|
|
<tbody>{run_rows or '<tr><td colspan="4" class="muted">No runs yet.</td></tr>'}</tbody>
|
|
</table>
|
|
</section>
|
|
<section class="panel">
|
|
<h2>Approved Ability Map</h2>
|
|
{render_ability_map(asdict(ability_map), repository_id)}
|
|
</section>
|
|
</div>
|
|
<section class="panel" style="margin-top:18px">
|
|
<h2>Manual Registry Entry</h2>
|
|
<div class="grid">
|
|
<form class="stack" method="post" action="/ui/repos/{repository_id}/abilities">
|
|
<h3>Add Ability</h3>
|
|
<label>Name <input name="name" required></label>
|
|
<label>Description <textarea name="description" rows="2"></textarea></label>
|
|
<label>Confidence <input name="confidence" type="number" min="0" max="1" step="0.01" value="1.0" required></label>
|
|
<button type="submit">Add Ability</button>
|
|
</form>
|
|
<form class="stack" method="post" action="/ui/repos/{repository_id}/capabilities">
|
|
<h3>Add Capability</h3>
|
|
<label>Ability ID <input name="ability_id" type="number" min="1" required></label>
|
|
<label>Name <input name="name" required></label>
|
|
<label>Description <textarea name="description" rows="2"></textarea></label>
|
|
<label>Inputs <input name="inputs" placeholder="Comma-separated"></label>
|
|
<label>Outputs <input name="outputs" placeholder="Comma-separated"></label>
|
|
<label>Confidence <input name="confidence" type="number" min="0" max="1" step="0.01" value="1.0" required></label>
|
|
<button type="submit">Add Capability</button>
|
|
</form>
|
|
<form class="stack" method="post" action="/ui/repos/{repository_id}/features">
|
|
<h3>Add Feature</h3>
|
|
<label>Capability ID <input name="capability_id" type="number" min="1" required></label>
|
|
<label>Name <input name="name" required></label>
|
|
<label>Type <input name="type" required></label>
|
|
<label>Location <input name="location"></label>
|
|
<label>Confidence <input name="confidence" type="number" min="0" max="1" step="0.01" value="1.0" required></label>
|
|
<button type="submit">Add Feature</button>
|
|
</form>
|
|
<form class="stack" method="post" action="/ui/repos/{repository_id}/evidence">
|
|
<h3>Add Evidence</h3>
|
|
<label>Capability ID <input name="capability_id" type="number" min="1" required></label>
|
|
<label>Type <input name="type" required></label>
|
|
<label>Reference <input name="reference" required></label>
|
|
<label>Strength <input name="strength" value="medium" required></label>
|
|
<button type="submit">Add Evidence</button>
|
|
</form>
|
|
</div>
|
|
</section>
|
|
<section class="panel" style="margin-top:18px">
|
|
<h2>Review Decisions</h2>
|
|
{render_review_decisions(decisions)}
|
|
</section>
|
|
"""
|
|
return page(repository.name, body)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/edit")
|
|
def edit_repository_from_form(
|
|
repository_id: int,
|
|
name: str = Form(...),
|
|
description: str = Form(""),
|
|
branch: str = Form("main"),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.update_repository(
|
|
repository_id,
|
|
name=name,
|
|
description=description,
|
|
branch=branch or "main",
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/abilities")
|
|
def create_ability_from_form(
|
|
repository_id: int,
|
|
name: str = Form(...),
|
|
description: str = Form(""),
|
|
confidence: float = Form(1.0),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.add_ability(
|
|
repository_id,
|
|
name=name,
|
|
description=description,
|
|
confidence=confidence,
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/capabilities")
|
|
def create_capability_from_form(
|
|
repository_id: int,
|
|
ability_id: int = Form(...),
|
|
name: str = Form(...),
|
|
description: str = Form(""),
|
|
inputs: str = Form(""),
|
|
outputs: str = Form(""),
|
|
confidence: float = Form(1.0),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.add_capability(
|
|
repository_id,
|
|
ability_id,
|
|
name=name,
|
|
description=description,
|
|
inputs=split_csv(inputs),
|
|
outputs=split_csv(outputs),
|
|
confidence=confidence,
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/features")
|
|
def create_feature_from_form(
|
|
repository_id: int,
|
|
capability_id: int = Form(...),
|
|
name: str = Form(...),
|
|
type: str = Form(...),
|
|
location: str = Form(""),
|
|
confidence: float = Form(1.0),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.add_feature(
|
|
repository_id,
|
|
capability_id,
|
|
name=name,
|
|
type=type,
|
|
location=location,
|
|
confidence=confidence,
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/evidence")
|
|
def create_evidence_from_form(
|
|
repository_id: int,
|
|
capability_id: int = Form(...),
|
|
type: str = Form(...),
|
|
reference: str = Form(...),
|
|
strength: str = Form("medium"),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.add_evidence(
|
|
repository_id,
|
|
capability_id,
|
|
type=type,
|
|
reference=reference,
|
|
strength=strength,
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/abilities/{ability_id}/edit")
|
|
def edit_ability_from_form(
|
|
repository_id: int,
|
|
ability_id: int,
|
|
name: str = Form(...),
|
|
description: str = Form(""),
|
|
confidence: float = Form(1.0),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.update_ability(
|
|
repository_id,
|
|
ability_id,
|
|
name=name,
|
|
description=description,
|
|
confidence=confidence,
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/abilities/{ability_id}/delete")
|
|
def delete_ability_from_form(
|
|
repository_id: int,
|
|
ability_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.delete_ability(repository_id, ability_id)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/capabilities/{capability_id}/edit")
|
|
def edit_capability_from_form(
|
|
repository_id: int,
|
|
capability_id: int,
|
|
name: str = Form(...),
|
|
description: str = Form(""),
|
|
inputs: str = Form(""),
|
|
outputs: str = Form(""),
|
|
confidence: float = Form(1.0),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.update_capability(
|
|
repository_id,
|
|
capability_id,
|
|
name=name,
|
|
description=description,
|
|
inputs=split_csv(inputs),
|
|
outputs=split_csv(outputs),
|
|
confidence=confidence,
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/capabilities/{capability_id}/delete")
|
|
def delete_capability_from_form(
|
|
repository_id: int,
|
|
capability_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.delete_capability(repository_id, capability_id)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/features/{feature_id}/edit")
|
|
def edit_feature_from_form(
|
|
repository_id: int,
|
|
feature_id: int,
|
|
name: str = Form(...),
|
|
type: str = Form(...),
|
|
location: str = Form(""),
|
|
confidence: float = Form(1.0),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.update_feature(
|
|
repository_id,
|
|
feature_id,
|
|
name=name,
|
|
type=type,
|
|
location=location,
|
|
confidence=confidence,
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/features/{feature_id}/delete")
|
|
def delete_feature_from_form(
|
|
repository_id: int,
|
|
feature_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.delete_feature(repository_id, feature_id)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/evidence/{evidence_id}/edit")
|
|
def edit_evidence_from_form(
|
|
repository_id: int,
|
|
evidence_id: int,
|
|
type: str = Form(...),
|
|
reference: str = Form(...),
|
|
strength: str = Form("medium"),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.update_evidence(
|
|
repository_id,
|
|
evidence_id,
|
|
type=type,
|
|
reference=reference,
|
|
strength=strength,
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/evidence/{evidence_id}/delete")
|
|
def delete_evidence_from_form(
|
|
repository_id: int,
|
|
evidence_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.delete_evidence(repository_id, evidence_id)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/analysis-runs")
|
|
def create_analysis_run_from_form(
|
|
repository_id: int,
|
|
source_path: str = Form(""),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
summary = service.analyze_repository(
|
|
repository_id,
|
|
source_path=source_path or None,
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{summary.analysis_run.id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.get("/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}")
|
|
def analysis_run_detail(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> HTMLResponse:
|
|
repository = service.get_repository(repository_id)
|
|
candidate_graph = service.candidate_graph(repository_id, analysis_run_id)
|
|
facts = service.list_observed_facts(repository_id, analysis_run_id)
|
|
decisions = service.list_review_decisions(repository_id, analysis_run_id)
|
|
fact_rows = "\n".join(
|
|
f"""
|
|
<tr>
|
|
<td>{escape(fact.kind)}</td>
|
|
<td>{escape(fact.name)}</td>
|
|
<td class="source">{escape(fact.path)}</td>
|
|
<td class="source">{escape(fact.value)}</td>
|
|
</tr>
|
|
"""
|
|
for fact in facts
|
|
)
|
|
body = f"""
|
|
<div class="actions">
|
|
<h1 style="margin-right:auto">{escape(repository.name)} · Run #{analysis_run_id}</h1>
|
|
<a class="button secondary" href="/ui/repos/{repository_id}">Repository</a>
|
|
</div>
|
|
<div class="grid">
|
|
<section class="panel">
|
|
<div class="actions">
|
|
<h2 style="margin-right:auto">Candidate Graph</h2>
|
|
<form method="post" action="/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}/candidate-graph/approve">
|
|
<button type="submit">Approve</button>
|
|
</form>
|
|
</div>
|
|
{render_candidate_graph(asdict(candidate_graph), repository_id, analysis_run_id)}
|
|
</section>
|
|
<section class="panel">
|
|
<h2>Observed Facts</h2>
|
|
<table>
|
|
<thead><tr><th>Kind</th><th>Name</th><th>Path</th><th>Value</th></tr></thead>
|
|
<tbody>{fact_rows or '<tr><td colspan="4" class="muted">No observed facts.</td></tr>'}</tbody>
|
|
</table>
|
|
<h2>Review Decisions</h2>
|
|
{render_review_decisions(decisions)}
|
|
</section>
|
|
</div>
|
|
"""
|
|
return page(f"{repository.name} Run {analysis_run_id}", body)
|
|
|
|
|
|
@router.post("/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}/candidate-graph/approve")
|
|
def approve_candidate_graph_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.approve_candidate_graph(
|
|
repository_id,
|
|
analysis_run_id,
|
|
notes="Approved from web UI",
|
|
)
|
|
return RedirectResponse(f"/ui/repos/{repository_id}", status_code=303)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-abilities/{candidate_ability_id}/reject"
|
|
)
|
|
def reject_candidate_ability_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
candidate_ability_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.reject_candidate_ability(
|
|
repository_id,
|
|
analysis_run_id,
|
|
candidate_ability_id,
|
|
notes="Rejected from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-capabilities/{candidate_capability_id}/reject"
|
|
)
|
|
def reject_candidate_capability_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
candidate_capability_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.reject_candidate_capability(
|
|
repository_id,
|
|
analysis_run_id,
|
|
candidate_capability_id,
|
|
notes="Rejected from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-features/{candidate_feature_id}/reject"
|
|
)
|
|
def reject_candidate_feature_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
candidate_feature_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.reject_candidate_feature(
|
|
repository_id,
|
|
analysis_run_id,
|
|
candidate_feature_id,
|
|
notes="Rejected from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-evidence/{candidate_evidence_id}/reject"
|
|
)
|
|
def reject_candidate_evidence_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
candidate_evidence_id: int,
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.reject_candidate_evidence(
|
|
repository_id,
|
|
analysis_run_id,
|
|
candidate_evidence_id,
|
|
notes="Rejected from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-abilities/{candidate_ability_id}/edit"
|
|
)
|
|
def edit_candidate_ability_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
candidate_ability_id: int,
|
|
name: str = Form(...),
|
|
description: str = Form(""),
|
|
confidence: float = Form(...),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.edit_candidate_ability(
|
|
repository_id,
|
|
analysis_run_id,
|
|
candidate_ability_id,
|
|
name=name,
|
|
description=description,
|
|
confidence=confidence,
|
|
notes="Edited from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-capabilities/{candidate_capability_id}/edit"
|
|
)
|
|
def edit_candidate_capability_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
candidate_capability_id: int,
|
|
name: str = Form(...),
|
|
description: str = Form(""),
|
|
confidence: float = Form(...),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.edit_candidate_capability(
|
|
repository_id,
|
|
analysis_run_id,
|
|
candidate_capability_id,
|
|
name=name,
|
|
description=description,
|
|
confidence=confidence,
|
|
notes="Edited from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-capabilities/{candidate_capability_id}/relink"
|
|
)
|
|
def relink_candidate_capability_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
candidate_capability_id: int,
|
|
target_ability_id: int = Form(...),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.relink_candidate_capability(
|
|
repository_id,
|
|
analysis_run_id,
|
|
candidate_capability_id,
|
|
target_ability_id=target_ability_id,
|
|
notes="Relinked from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-features/{candidate_feature_id}/relink"
|
|
)
|
|
def relink_candidate_feature_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
candidate_feature_id: int,
|
|
target_capability_id: int = Form(...),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.relink_candidate_feature(
|
|
repository_id,
|
|
analysis_run_id,
|
|
candidate_feature_id,
|
|
target_capability_id=target_capability_id,
|
|
notes="Relinked from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-evidence/{candidate_evidence_id}/relink"
|
|
)
|
|
def relink_candidate_evidence_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
candidate_evidence_id: int,
|
|
target_capability_id: int = Form(...),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.relink_candidate_evidence(
|
|
repository_id,
|
|
analysis_run_id,
|
|
candidate_evidence_id,
|
|
target_capability_id=target_capability_id,
|
|
notes="Relinked from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-abilities/{source_ability_id}/merge"
|
|
)
|
|
def merge_candidate_ability_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
source_ability_id: int,
|
|
target_ability_id: int = Form(...),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.merge_candidate_ability(
|
|
repository_id,
|
|
analysis_run_id,
|
|
source_ability_id,
|
|
target_ability_id=target_ability_id,
|
|
notes="Merged from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-capabilities/{source_capability_id}/merge"
|
|
)
|
|
def merge_candidate_capability_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
source_capability_id: int,
|
|
target_capability_id: int = Form(...),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.merge_candidate_capability(
|
|
repository_id,
|
|
analysis_run_id,
|
|
source_capability_id,
|
|
target_capability_id=target_capability_id,
|
|
notes="Merged from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-features/{source_feature_id}/merge"
|
|
)
|
|
def merge_candidate_feature_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
source_feature_id: int,
|
|
target_feature_id: int = Form(...),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.merge_candidate_feature(
|
|
repository_id,
|
|
analysis_run_id,
|
|
source_feature_id,
|
|
target_feature_id=target_feature_id,
|
|
notes="Merged from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
@router.post(
|
|
"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
"/candidate-evidence/{source_evidence_id}/merge"
|
|
)
|
|
def merge_candidate_evidence_from_form(
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
source_evidence_id: int,
|
|
target_evidence_id: int = Form(...),
|
|
service: RegistryService = Depends(get_service),
|
|
) -> RedirectResponse:
|
|
service.merge_candidate_evidence(
|
|
repository_id,
|
|
analysis_run_id,
|
|
source_evidence_id,
|
|
target_evidence_id=target_evidence_id,
|
|
notes="Merged from web UI",
|
|
)
|
|
return RedirectResponse(
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}",
|
|
status_code=303,
|
|
)
|
|
|
|
|
|
def render_candidate_graph(graph: dict, repository_id: int, analysis_run_id: int) -> str:
|
|
abilities = graph.get("abilities", [])
|
|
if not abilities:
|
|
return '<p class="muted">No candidates generated.</p>'
|
|
items = []
|
|
for ability in abilities:
|
|
capabilities = "".join(
|
|
render_candidate_capability(capability, repository_id, analysis_run_id)
|
|
for capability in ability["capabilities"]
|
|
)
|
|
items.append(
|
|
f"""
|
|
<li>
|
|
<strong>{escape(ability['name'])}</strong>
|
|
<span class="pill">ID {ability['id']}</span>
|
|
<span class="pill">{escape(ability['status'])}</span>
|
|
<span class="pill">{ability['confidence']:.2f}</span>
|
|
{render_candidate_ability_actions(ability, repository_id, analysis_run_id)}
|
|
<p class="muted">{escape(ability['description'])}</p>
|
|
{render_candidate_edit_form('candidate-abilities', ability, repository_id, analysis_run_id)}
|
|
{render_candidate_merge_form('candidate-abilities', ability, repository_id, analysis_run_id, 'target_ability_id', 'Merge into ability ID')}
|
|
{render_sources(ability['source_refs'])}
|
|
<ul>{capabilities}</ul>
|
|
</li>
|
|
"""
|
|
)
|
|
return f'<div class="tree"><ul>{"".join(items)}</ul></div>'
|
|
|
|
|
|
def render_repository_facts(languages: list[str], frameworks: list[str]) -> str:
|
|
if not languages and not frameworks:
|
|
return ""
|
|
language_pills = "".join(
|
|
f'<span class="pill">Language: {escape(language)}</span>'
|
|
for language in languages
|
|
)
|
|
framework_pills = "".join(
|
|
f'<span class="pill">Framework: {escape(framework)}</span>'
|
|
for framework in frameworks
|
|
)
|
|
return f'<p class="actions">{language_pills}{framework_pills}</p>'
|
|
|
|
|
|
def split_csv(value: str) -> list[str]:
|
|
return [item.strip() for item in value.split(",") if item.strip()]
|
|
|
|
|
|
def render_review_decisions(decisions: list) -> str:
|
|
if not decisions:
|
|
return '<p class="muted">No review decisions yet.</p>'
|
|
rows = "\n".join(
|
|
f"""
|
|
<tr>
|
|
<td>{escape(decision.action)}</td>
|
|
<td class="source">{escape(decision.created_at)}</td>
|
|
<td>{escape(decision.notes)}</td>
|
|
</tr>
|
|
"""
|
|
for decision in decisions
|
|
)
|
|
return f"""
|
|
<table>
|
|
<thead><tr><th>Action</th><th>Created</th><th>Notes</th></tr></thead>
|
|
<tbody>{rows}</tbody>
|
|
</table>
|
|
"""
|
|
|
|
|
|
def render_candidate_ability_actions(
|
|
ability: dict,
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
) -> str:
|
|
if ability["status"] != "candidate":
|
|
return ""
|
|
action = (
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
f"/candidate-abilities/{ability['id']}/reject"
|
|
)
|
|
return f"""
|
|
<form style="display:inline" method="post" action="{action}">
|
|
<button class="secondary" type="submit">Reject</button>
|
|
</form>
|
|
"""
|
|
|
|
|
|
def render_candidate_edit_form(
|
|
collection: str,
|
|
candidate: dict,
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
) -> str:
|
|
if candidate["status"] != "candidate":
|
|
return ""
|
|
action = (
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
f"/{collection}/{candidate['id']}/edit"
|
|
)
|
|
confidence = f"{candidate['confidence']:.2f}"
|
|
return f"""
|
|
<form class="stack" method="post" action="{action}">
|
|
<label>Name <input name="name" value="{escape(candidate['name'])}" required></label>
|
|
<label>Description <textarea name="description" rows="2">{escape(candidate['description'])}</textarea></label>
|
|
<label>Confidence <input name="confidence" type="number" min="0" max="1" step="0.01" value="{confidence}" required></label>
|
|
<button class="secondary" type="submit">Save Edit</button>
|
|
</form>
|
|
"""
|
|
|
|
|
|
def render_candidate_capability(
|
|
capability: dict,
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
) -> str:
|
|
features = "".join(
|
|
render_candidate_feature(feature, repository_id, analysis_run_id)
|
|
for feature in capability["features"]
|
|
)
|
|
evidence = "".join(
|
|
render_candidate_evidence(item, repository_id, analysis_run_id)
|
|
for item in capability["evidence"]
|
|
)
|
|
return f"""
|
|
<li>
|
|
<strong>{escape(capability['name'])}</strong>
|
|
<span class="pill">ID {capability['id']}</span>
|
|
<span class="pill">{escape(capability['status'])}</span>
|
|
<span class="pill">{capability['confidence']:.2f}</span>
|
|
{render_candidate_reject_form('candidate-capabilities', capability, repository_id, analysis_run_id)}
|
|
<p class="muted">{escape(capability['description'])}</p>
|
|
{render_candidate_edit_form('candidate-capabilities', capability, repository_id, analysis_run_id)}
|
|
{render_candidate_relink_form('candidate-capabilities', capability, repository_id, analysis_run_id, 'target_ability_id', 'Target ability ID')}
|
|
{render_candidate_merge_form('candidate-capabilities', capability, repository_id, analysis_run_id, 'target_capability_id', 'Merge into capability ID')}
|
|
{render_sources(capability['source_refs'])}
|
|
<h3>Features</h3>
|
|
<ul>{features or '<li class="muted">No feature candidates.</li>'}</ul>
|
|
<h3>Evidence</h3>
|
|
<ul>{evidence or '<li class="muted">No evidence candidates.</li>'}</ul>
|
|
</li>
|
|
"""
|
|
|
|
|
|
def render_candidate_feature(
|
|
feature: dict,
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
) -> str:
|
|
return f"""
|
|
<li>
|
|
{escape(feature["name"])}
|
|
<span class="pill">ID {feature["id"]}</span>
|
|
<span class="pill">{escape(feature["status"])}</span>
|
|
<span class="pill">{escape(feature["type"])}</span>
|
|
<span class="source">{escape(feature["location"])}</span>
|
|
{render_candidate_reject_form('candidate-features', feature, repository_id, analysis_run_id)}
|
|
{render_candidate_relink_form('candidate-features', feature, repository_id, analysis_run_id, 'target_capability_id', 'Target capability ID')}
|
|
{render_candidate_merge_form('candidate-features', feature, repository_id, analysis_run_id, 'target_feature_id', 'Merge into feature ID')}
|
|
</li>
|
|
"""
|
|
|
|
|
|
def render_candidate_evidence(
|
|
evidence: dict,
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
) -> str:
|
|
return f"""
|
|
<li>
|
|
{escape(evidence["type"])}
|
|
<span class="pill">ID {evidence["id"]}</span>
|
|
<span class="pill">{escape(evidence["status"])}</span>
|
|
<span class="pill">{escape(evidence["strength"])}</span>
|
|
<span class="source">{escape(evidence["reference"])}</span>
|
|
{render_candidate_reject_form('candidate-evidence', evidence, repository_id, analysis_run_id)}
|
|
{render_candidate_relink_form('candidate-evidence', evidence, repository_id, analysis_run_id, 'target_capability_id', 'Target capability ID')}
|
|
{render_candidate_merge_form('candidate-evidence', evidence, repository_id, analysis_run_id, 'target_evidence_id', 'Merge into evidence ID')}
|
|
</li>
|
|
"""
|
|
|
|
|
|
def render_candidate_reject_form(
|
|
collection: str,
|
|
candidate: dict,
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
) -> str:
|
|
if candidate["status"] != "candidate":
|
|
return ""
|
|
action = (
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
f"/{collection}/{candidate['id']}/reject"
|
|
)
|
|
return f"""
|
|
<form style="display:inline" method="post" action="{action}">
|
|
<button class="secondary" type="submit">Reject</button>
|
|
</form>
|
|
"""
|
|
|
|
|
|
def render_candidate_relink_form(
|
|
collection: str,
|
|
candidate: dict,
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
field_name: str,
|
|
label: str,
|
|
) -> str:
|
|
if candidate["status"] != "candidate":
|
|
return ""
|
|
action = (
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
f"/{collection}/{candidate['id']}/relink"
|
|
)
|
|
return f"""
|
|
<form style="display:inline-grid; grid-template-columns: 120px auto; gap: 6px; align-items: end;" method="post" action="{action}">
|
|
<label>{label}<input name="{field_name}" type="number" min="1" required></label>
|
|
<button class="secondary" type="submit">Relink</button>
|
|
</form>
|
|
"""
|
|
|
|
|
|
def render_candidate_merge_form(
|
|
collection: str,
|
|
candidate: dict,
|
|
repository_id: int,
|
|
analysis_run_id: int,
|
|
field_name: str,
|
|
label: str,
|
|
) -> str:
|
|
if candidate["status"] != "candidate":
|
|
return ""
|
|
action = (
|
|
f"/ui/repos/{repository_id}/analysis-runs/{analysis_run_id}"
|
|
f"/{collection}/{candidate['id']}/merge"
|
|
)
|
|
return f"""
|
|
<form style="display:inline-grid; grid-template-columns: 140px auto; gap: 6px; align-items: end;" method="post" action="{action}">
|
|
<label>{label}<input name="{field_name}" type="number" min="1" required></label>
|
|
<button class="secondary" type="submit">Merge</button>
|
|
</form>
|
|
"""
|
|
|
|
|
|
def render_ability_map(ability_map: dict, repository_id: int) -> str:
|
|
abilities = ability_map.get("abilities", [])
|
|
if not abilities:
|
|
return '<p class="muted">No approved entries yet.</p>'
|
|
items = []
|
|
for ability in abilities:
|
|
capabilities = []
|
|
for capability in ability["capabilities"]:
|
|
features = "".join(
|
|
render_approved_feature(feature, repository_id)
|
|
for feature in capability["features"]
|
|
)
|
|
evidence = "".join(
|
|
render_approved_evidence(item, repository_id)
|
|
for item in capability["evidence"]
|
|
)
|
|
capabilities.append(
|
|
f"""
|
|
<li id="capability-{capability['id']}">
|
|
<strong>{escape(capability['name'])}</strong>
|
|
<span class="pill">ID {capability['id']}</span>
|
|
<p class="muted">{escape(capability['description'])}</p>
|
|
{render_approved_capability_forms(capability, repository_id)}
|
|
<ul>{features}{evidence}</ul>
|
|
</li>
|
|
"""
|
|
)
|
|
items.append(
|
|
f"""
|
|
<li id="ability-{ability['id']}">
|
|
<strong>{escape(ability['name'])}</strong>
|
|
<span class="pill">ID {ability['id']}</span>
|
|
<p class="muted">{escape(ability['description'])}</p>
|
|
{render_approved_ability_forms(ability, repository_id)}
|
|
<ul>{''.join(capabilities)}</ul>
|
|
</li>
|
|
"""
|
|
)
|
|
return f'<div class="tree"><ul>{"".join(items)}</ul></div>'
|
|
|
|
|
|
def render_approved_ability_forms(ability: dict, repository_id: int) -> str:
|
|
return f"""
|
|
<form class="stack" method="post" action="/ui/repos/{repository_id}/abilities/{ability['id']}/edit">
|
|
<label>Name <input name="name" value="{escape(ability['name'])}" required></label>
|
|
<label>Description <textarea name="description" rows="2">{escape(ability['description'])}</textarea></label>
|
|
<label>Confidence <input name="confidence" type="number" min="0" max="1" step="0.01" value="{ability['confidence']:.2f}" required></label>
|
|
<div class="actions">
|
|
<button class="secondary" type="submit">Save Ability</button>
|
|
</div>
|
|
</form>
|
|
<form method="post" action="/ui/repos/{repository_id}/abilities/{ability['id']}/delete">
|
|
<button class="secondary" type="submit">Delete Ability</button>
|
|
</form>
|
|
"""
|
|
|
|
|
|
def render_approved_capability_forms(capability: dict, repository_id: int) -> str:
|
|
inputs = ", ".join(capability["inputs"])
|
|
outputs = ", ".join(capability["outputs"])
|
|
return f"""
|
|
<form class="stack" method="post" action="/ui/repos/{repository_id}/capabilities/{capability['id']}/edit">
|
|
<label>Name <input name="name" value="{escape(capability['name'])}" required></label>
|
|
<label>Description <textarea name="description" rows="2">{escape(capability['description'])}</textarea></label>
|
|
<label>Inputs <input name="inputs" value="{escape(inputs)}"></label>
|
|
<label>Outputs <input name="outputs" value="{escape(outputs)}"></label>
|
|
<label>Confidence <input name="confidence" type="number" min="0" max="1" step="0.01" value="{capability['confidence']:.2f}" required></label>
|
|
<div class="actions">
|
|
<button class="secondary" type="submit">Save Capability</button>
|
|
</div>
|
|
</form>
|
|
<form method="post" action="/ui/repos/{repository_id}/capabilities/{capability['id']}/delete">
|
|
<button class="secondary" type="submit">Delete Capability</button>
|
|
</form>
|
|
"""
|
|
|
|
|
|
def render_approved_feature(feature: dict, repository_id: int) -> str:
|
|
return f"""
|
|
<li>
|
|
{escape(feature["name"])}
|
|
<span class="pill">{escape(feature["type"])}</span>
|
|
<span class="source">{escape(feature["location"])}</span>
|
|
{render_sources(feature.get("source_refs", []))}
|
|
<form class="stack" method="post" action="/ui/repos/{repository_id}/features/{feature['id']}/edit">
|
|
<label>Name <input name="name" value="{escape(feature['name'])}" required></label>
|
|
<label>Type <input name="type" value="{escape(feature['type'])}" required></label>
|
|
<label>Location <input name="location" value="{escape(feature['location'])}"></label>
|
|
<label>Confidence <input name="confidence" type="number" min="0" max="1" step="0.01" value="{feature['confidence']:.2f}" required></label>
|
|
<button class="secondary" type="submit">Save Feature</button>
|
|
</form>
|
|
<form method="post" action="/ui/repos/{repository_id}/features/{feature['id']}/delete">
|
|
<button class="secondary" type="submit">Delete Feature</button>
|
|
</form>
|
|
</li>
|
|
"""
|
|
|
|
|
|
def render_approved_evidence(evidence: dict, repository_id: int) -> str:
|
|
return f"""
|
|
<li>
|
|
{escape(evidence["type"])}
|
|
<span class="pill">{escape(evidence["strength"])}</span>
|
|
<span class="source">{escape(evidence["reference"])}</span>
|
|
{render_sources(evidence.get("source_refs", []))}
|
|
<form class="stack" method="post" action="/ui/repos/{repository_id}/evidence/{evidence['id']}/edit">
|
|
<label>Type <input name="type" value="{escape(evidence['type'])}" required></label>
|
|
<label>Reference <input name="reference" value="{escape(evidence['reference'])}" required></label>
|
|
<label>Strength <input name="strength" value="{escape(evidence['strength'])}" required></label>
|
|
<button class="secondary" type="submit">Save Evidence</button>
|
|
</form>
|
|
<form method="post" action="/ui/repos/{repository_id}/evidence/{evidence['id']}/delete">
|
|
<button class="secondary" type="submit">Delete Evidence</button>
|
|
</form>
|
|
</li>
|
|
"""
|
|
|
|
|
|
def search_result_href(result: dict) -> str:
|
|
href = f"/ui/repos/{result['repository_id']}"
|
|
if result.get("capability_id"):
|
|
return f"{href}#capability-{result['capability_id']}"
|
|
if result.get("ability_id"):
|
|
return f"{href}#ability-{result['ability_id']}"
|
|
return href
|
|
|
|
|
|
def render_sources(source_refs: list[dict]) -> str:
|
|
if not source_refs:
|
|
return ""
|
|
sources = ", ".join(
|
|
f'<span class="source">{escape(ref["kind"])}:{escape(source_ref_label(ref))}</span>'
|
|
for ref in source_refs[:5]
|
|
)
|
|
if len(source_refs) > 5:
|
|
sources += f' <span class="muted">+{len(source_refs) - 5} more</span>'
|
|
return f"<p>{sources}</p>"
|
|
|
|
|
|
def source_ref_label(ref: dict) -> str:
|
|
label = ref["path"] or ref["name"]
|
|
if ref.get("line"):
|
|
label = f"{label}:{ref['line']}"
|
|
return label
|
|
|
|
|
|
def render_search_context(result: dict) -> str:
|
|
details = []
|
|
if result.get("ability_name"):
|
|
details.append(f"Ability: {escape(result['ability_name'])}")
|
|
if result.get("capability_name"):
|
|
details.append(f"Capability: {escape(result['capability_name'])}")
|
|
if result.get("evidence_level"):
|
|
details.append(f"Evidence: {escape(result['evidence_level'])}")
|
|
if result.get("source_reference"):
|
|
details.append(f"Source: {escape(result['source_reference'])}")
|
|
if result.get("match_description"):
|
|
details.append(escape(result["match_description"]))
|
|
if not details:
|
|
return ""
|
|
return f'<p class="muted">{" · ".join(details)}</p>'
|