Add world-class preflight HTML cockpit

This commit is contained in:
yaojingang
2026-06-16 02:45:01 +08:00
parent 858d96b8c5
commit f6d3bb523f
34 changed files with 859 additions and 81 deletions
+1
View File
@@ -43,6 +43,7 @@ IGNORED_FILE_PATTERNS = {
"reports/skill-overview*.json",
"reports/world_class_evidence_preflight*.json",
"reports/world_class_evidence_preflight*.md",
"reports/world_class_evidence_preflight*.html",
"reports/*pattern-analysis*.md",
"reports/*research-plan*.md",
}
+7 -1
View File
@@ -522,6 +522,8 @@ def build_report(skill_dir: Path, generated_at: str) -> dict[str, Any]:
"directory": default_submissions_dir,
"drafts_count_as_evidence": False,
"preflight_counts_submission_as_completion": False,
"html_report": "reports/world_class_evidence_preflight.html",
"html_exists": True,
"prepare_submission": f"python3 scripts/yao.py world-class-submission-kit . --output-dir {default_submissions_dir}",
"validate_intake": f"python3 scripts/yao.py world-class-intake . --submissions-dir {default_submissions_dir}",
"submission_review": f"python3 scripts/yao.py world-class-submission-review . --submissions-dir {default_submissions_dir}",
@@ -534,6 +536,10 @@ def build_report(skill_dir: Path, generated_at: str) -> dict[str, Any]:
"preflight_counts_submission_as_completion": preflight_submissions.get(
"preflight_counts_submission_as_completion"
),
"html_report": world_class_preflight.get("artifacts", {}).get("html")
if isinstance(world_class_preflight.get("artifacts", {}), dict)
else None,
"html_exists": (skill_dir / "reports" / "world_class_evidence_preflight.html").exists(),
"prepare_submission": preflight_commands.get("prepare_submission"),
"validate_intake": preflight_commands.get("validate_intake"),
"submission_review": preflight_commands.get("submission_review"),
@@ -546,7 +552,7 @@ def build_report(skill_dir: Path, generated_at: str) -> dict[str, Any]:
label="Preflight exposes a safe submission-kit handoff",
expected=expected_preflight_handoff,
actual=actual_preflight_handoff,
paths=[REQUIRED_REPORTS["world_class_preflight"]],
paths=[REQUIRED_REPORTS["world_class_preflight"], "reports/world_class_evidence_preflight.html"],
detail=(
"Preflight must give operators the exact draft, intake, review, ledger, and claim-guard commands "
"without letting drafts or submissions count as accepted evidence."
+211
View File
@@ -7,6 +7,7 @@ from datetime import date
from pathlib import Path
from typing import Any
from html_rendering import html_text
from render_world_class_evidence_intake import build_intake
from render_world_class_evidence_ledger import build_ledger
from render_world_class_submission_review import build_submission_review
@@ -336,6 +337,7 @@ def build_preflight(skill_dir: Path, generated_at: str, submissions_dir: Path |
"artifacts": {
"json": "reports/world_class_evidence_preflight.json",
"markdown": "reports/world_class_evidence_preflight.md",
"html": "reports/world_class_evidence_preflight.html",
},
}
@@ -430,12 +432,216 @@ def render_markdown(report: dict[str, Any]) -> str:
return "\n".join(lines).rstrip() + "\n"
def html_list(values: list[Any], empty: str) -> str:
if not values:
return f"<li>{html_text(empty)}</li>"
return "".join(f"<li>{html_text(value)}</li>" for value in values)
def render_html_commands(commands: dict[str, str]) -> str:
return "".join(
f"<li><span>{html_text(label.replace('_', ' '))}</span><code>{html_text(command)}</code></li>"
for label, command in commands.items()
)
def render_html_prechecks(rows: list[dict[str, Any]]) -> str:
if not rows:
return "<p class=\"muted\">No prechecks listed.</p>"
return "".join(
"""
<article class="check-row {status}">
<div>
<span>{kind}</span>
<strong>{label}</strong>
</div>
<dl>
<dt>Current</dt><dd><code>{actual}</code></dd>
<dt>Status</dt><dd>{status}</dd>
<dt>Action</dt><dd>{action}</dd>
</dl>
</article>
""".format(
status=html_text(row.get("status", "")),
kind=html_text(row.get("kind", "")),
label=html_text(row.get("label", "")),
actual=html_text(row.get("actual", "")),
action=html_text(row.get("next_action", "")),
)
for row in rows
)
def render_html_source_checks(rows: list[dict[str, Any]]) -> str:
if not rows:
return "<p class=\"muted\">No source checks listed.</p>"
return "".join(
"""
<article class="check-row {status}">
<div>
<span>{field}</span>
<strong>{label}</strong>
</div>
<dl>
<dt>Current</dt><dd><code>{actual}</code></dd>
<dt>Expected</dt><dd><code>{expected}</code></dd>
<dt>Status</dt><dd>{status}</dd>
<dt>Action</dt><dd>{action}</dd>
</dl>
</article>
""".format(
status=html_text(row.get("status", "")),
field=html_text(row.get("field", "")),
label=html_text(row.get("label", "")),
actual=html_text(row.get("actual", "")),
expected=html_text(row.get("expected", "")),
action=html_text(row.get("next_action", "")),
)
for row in rows
)
def render_html_item(item: dict[str, Any]) -> str:
return f"""
<article class="evidence-card {html_text(item.get('status', ''))}">
<header>
<span>{html_text(item.get('category', ''))} · {html_text(item.get('status', ''))}</span>
<h3>{html_text(item.get('label', item.get('evidence_key', '')))}</h3>
</header>
<dl class="meta">
<dt>Evidence</dt><dd><code>{html_text(item.get('evidence_key', ''))}</code></dd>
<dt>Ledger</dt><dd>{html_text(item.get('ledger_status', ''))}</dd>
<dt>Intake</dt><dd>{html_text(item.get('intake_readiness', ''))}</dd>
<dt>Review</dt><dd>{html_text(item.get('review_state', ''))}</dd>
<dt>Draft</dt><dd><code>{html_text(item.get('submission_path', ''))}</code></dd>
</dl>
<section class="next-action">
<h4>Next Action</h4>
<p>{html_text(item.get('next_action', ''))}</p>
<code>{html_text(item.get('commands', {}).get('prepare_submission', ''))}</code>
</section>
<section class="check-section">
<h4>Prechecks</h4>
<div class="check-grid">{render_html_prechecks(item.get('prechecks', []))}</div>
</section>
<section class="check-section">
<h4>Source Checks</h4>
<div class="check-grid">{render_html_source_checks(item.get('source_checklist', []))}</div>
</section>
<section class="runbook">
<h4>Runbook</h4>
<ul>{html_list(item.get('runbook', []), 'No runbook steps listed.')}</ul>
</section>
</article>
"""
def render_html(report: dict[str, Any]) -> str:
summary = report["summary"]
stats = [
("Decision", summary["decision"]),
("Pending", summary["pending_count"]),
("Ready", summary["collection_ready_count"]),
("Blocked", summary["collection_blocked_count"]),
("Source", f"{summary['source_pass_count']}/{summary['source_check_count']}"),
]
stat_html = "".join(
f"<article><span>{html_text(label)}</span><strong>{html_text(value)}</strong></article>"
for label, value in stats
)
item_cards = "".join(render_html_item(item) for item in report.get("items", []))
return f"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>World-Class Evidence Preflight</title>
<style>
:root {{ --ink:#1B365D; --text:#202124; --muted:#6f6a63; --line:#e8e1d8; --soft:#f8f6f2; --warn:#9b4d0f; --pass:#1f6f43; --block:#8a1f11; }}
* {{ box-sizing:border-box; }}
body {{ margin:0; background:#fff; color:var(--text); font:16px/1.55 Georgia, "Times New Roman", serif; }}
.topbar {{ position:sticky; top:0; z-index:10; background:rgba(255,255,255,.96); border-bottom:1px solid var(--line); }}
.topbar-inner {{ max-width:1180px; margin:0 auto; padding:12px 24px; display:flex; justify-content:space-between; gap:16px; align-items:center; }}
.brand, a, h1, h2, h3, h4 {{ color:var(--ink); }}
.links {{ display:flex; gap:14px; flex-wrap:wrap; }}
.links a {{ text-decoration:none; }}
.shell {{ max-width:1180px; margin:0 auto; padding:36px 24px 72px; }}
.hero {{ border-bottom:1px solid var(--line); padding:32px 0 28px; }}
.eyebrow {{ color:var(--ink); font-size:12px; text-transform:uppercase; font-weight:700; letter-spacing:0; }}
h1 {{ margin:8px 0 12px; font-size:56px; line-height:1.04; letter-spacing:0; }}
h2 {{ margin:0 0 14px; font-size:30px; letter-spacing:0; }}
h3 {{ margin:4px 0 10px; font-size:22px; letter-spacing:0; }}
h4 {{ margin:0 0 8px; font-size:16px; letter-spacing:0; }}
.lede {{ max-width:820px; color:var(--muted); font-size:20px; }}
.stats {{ display:grid; grid-template-columns:repeat(5, minmax(0,1fr)); gap:12px; margin:26px 0 0; }}
.stats article, .panel, .evidence-card, .check-row {{ border:1px solid var(--line); border-radius:8px; background:#fff; }}
.stats article {{ padding:16px; }}
.stats span, .muted, .evidence-card header span, .check-row span {{ color:var(--muted); }}
.stats strong {{ display:block; color:var(--ink); font-size:28px; line-height:1.15; overflow-wrap:anywhere; }}
.section {{ padding:32px 0; border-bottom:1px solid var(--line); }}
.two-col {{ display:grid; grid-template-columns:minmax(0,.45fr) minmax(0,1fr); gap:18px; align-items:start; }}
.panel {{ padding:20px; min-width:0; }}
.commands {{ list-style:none; padding:0; margin:0; display:grid; gap:10px; }}
.commands li {{ padding:12px; background:var(--soft); border-radius:8px; }}
.commands span {{ display:block; color:var(--ink); font-weight:700; margin-bottom:4px; }}
.evidence-grid {{ display:grid; gap:18px; }}
.evidence-card {{ padding:20px; min-width:0; }}
.evidence-card.blocked {{ border-left:4px solid var(--block); }}
.evidence-card.ready-for-human-review, .evidence-card.ready-to-collect, .check-row.human-required, .check-row.external-required, .check-row.missing, .check-row.blocked {{ border-left:4px solid var(--warn); }}
.evidence-card.ready-for-submission, .check-row.pass {{ border-left:4px solid var(--pass); }}
.meta, .check-row dl {{ display:grid; grid-template-columns:96px minmax(0,1fr); gap:8px 12px; }}
dt {{ color:var(--ink); }}
dd {{ margin:0; min-width:0; overflow-wrap:anywhere; }}
code {{ font-family:ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size:13px; overflow-wrap:anywhere; }}
.next-action, .runbook {{ background:var(--soft); border-radius:8px; padding:14px; margin:14px 0; }}
.next-action p {{ margin-top:0; }}
.check-grid {{ display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:12px; }}
.check-row {{ padding:14px; min-width:0; }}
.check-section {{ margin-top:16px; }}
.notice {{ background:var(--soft); border-left:4px solid var(--ink); padding:16px; border-radius:8px; }}
li {{ overflow-wrap:anywhere; }}
@media (max-width:820px) {{ .stats, .two-col, .check-grid {{ grid-template-columns:1fr; }} h1 {{ font-size:38px; }} .topbar-inner {{ align-items:flex-start; flex-direction:column; }} }}
</style>
</head>
<body>
<nav class="topbar"><div class="topbar-inner"><span class="brand">World-Class Preflight</span><div class="links"><a href="#handoff">Handoff</a><a href="#queue">Queue</a><a href="#boundary">Boundary</a></div></div></nav>
<main class="shell">
<section class="hero">
<span class="eyebrow">Evidence Collection</span>
<h1>World-Class Evidence Preflight</h1>
<p class="lede">This operator view shows which external and human evidence is still blocked, which commands prepare editable submission drafts, and why preflight never counts as accepted evidence.</p>
<div class="stats">{stat_html}</div>
</section>
<section class="section two-col" id="handoff">
<article class="panel">
<h2>Submission Kit</h2>
<p class="muted">Generate drafts only after real provider, human-review, native-permission, or native-client work exists. Drafts remain non-evidence until valid aggregate artifact refs and SHA-256 digests are supplied.</p>
<ul>
<li>submissions directory: <code>{html_text(report['submissions']['directory'])}</code></li>
<li>drafts count as evidence: <code>{html_text(str(report['submissions']['drafts_count_as_evidence']).lower())}</code></li>
<li>preflight accepts evidence: <code>{html_text(str(report['summary']['preflight_counts_as_evidence']).lower())}</code></li>
</ul>
</article>
<aside class="panel"><h2>Commands</h2><ul class="commands">{render_html_commands(report['submissions']['commands'])}</ul></aside>
</section>
<section class="section" id="queue"><h2>Evidence Queue</h2><div class="evidence-grid">{item_cards}</div></section>
<section class="section" id="boundary">
<h2>Safety Boundary</h2>
<div class="notice"><ul><li>Environment variables are displayed only as set or not-set; secret values are never printed.</li><li>Human-required and external-required states are operator work, not accepted evidence.</li><li>The world-class ledger remains the only source of truth for ready_to_claim_world_class.</li></ul></div>
</section>
</main>
</body>
</html>
"""
def main() -> None:
parser = argparse.ArgumentParser(description="Render collection preflight checks for pending world-class evidence.")
parser.add_argument("skill_dir", nargs="?", default=".")
parser.add_argument("--submissions-dir")
parser.add_argument("--output-json", default="reports/world_class_evidence_preflight.json")
parser.add_argument("--output-md", default="reports/world_class_evidence_preflight.md")
parser.add_argument("--output-html", default="reports/world_class_evidence_preflight.html")
parser.add_argument("--generated-at", default=date.today().isoformat())
args = parser.parse_args()
@@ -444,14 +650,19 @@ def main() -> None:
report = build_preflight(skill_dir, args.generated_at, submissions_dir=submissions_dir)
output_json = Path(args.output_json)
output_md = Path(args.output_md)
output_html = Path(args.output_html)
if not output_json.is_absolute():
output_json = skill_dir / output_json
if not output_md.is_absolute():
output_md = skill_dir / output_md
if not output_html.is_absolute():
output_html = skill_dir / output_html
output_json.parent.mkdir(parents=True, exist_ok=True)
output_md.parent.mkdir(parents=True, exist_ok=True)
output_html.parent.mkdir(parents=True, exist_ok=True)
output_json.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
output_md.write_text(render_markdown(report), encoding="utf-8")
output_html.write_text(render_html(report), encoding="utf-8")
print(json.dumps(report, ensure_ascii=False, indent=2))
+1
View File
@@ -31,6 +31,7 @@ IGNORED_FILE_PATTERNS = {
"reports/skill-overview*.json",
"reports/world_class_evidence_preflight*.json",
"reports/world_class_evidence_preflight*.md",
"reports/world_class_evidence_preflight*.html",
"reports/*pattern-analysis*.md",
"reports/*research-plan*.md",
}
+1
View File
@@ -225,6 +225,7 @@ def build_parser(command_handlers: dict[str, Callable[[argparse.Namespace], int]
world_class_preflight_cmd.add_argument("--submissions-dir")
world_class_preflight_cmd.add_argument("--output-json")
world_class_preflight_cmd.add_argument("--output-md")
world_class_preflight_cmd.add_argument("--output-html")
world_class_preflight_cmd.add_argument("--generated-at")
world_class_preflight_cmd.set_defaults(func=_handler(command_handlers, "command_world_class_preflight"))