Existing frontend: detect, report, then keep or restyle (ticket 03)
- templates/detect_frontend.py: finds plain HTML, React/Vue/Angular/Svelte apps and PyQt web views; prints location, stack, main colours, font and every token block (CSS custom properties, <style> tags, Tailwind config). - templates/frontend.md: shared report / keep / restyle procedure, written so rpa-dashboard-ai can point to it. - SKILL.md steps 1, 2 and 6 point to it. - tests: detection self-check; fixture c-web-existing-frontend; eval entries c-keep and c-restyle (new pages only, per-question grading, checks on what changed in the existing files), both passing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3eb3fdf00e
commit
f11bddd958
15 files changed
+1210
-12
No files matched your search
+59
-4
@@ -9,6 +9,7 @@ prompt (`-p` can't answer questions). It then grades the reply, runs the Seam 1
|
||||
check on the page it built, and writes tests/evals/results/<fixture>.json.
|
||||
Exit code 0 means every check passed.
|
||||
"""
|
||||
import difflib
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
@@ -36,14 +37,57 @@ FIXTURES = {
|
||||
"never_asks": [r"\bkeep\b|restyle"],
|
||||
"brand": "#7a3cff",
|
||||
},
|
||||
# (c) existing teal frontend in web/, run once per answer to keep-or-restyle.
|
||||
"c-keep": {
|
||||
"fixture": "c-web-existing-frontend",
|
||||
"prompt": "Build me an RPA dashboard for this project. I can't answer questions while you "
|
||||
"work, so here are my answers to anything the skill asks. Keep or restyle the "
|
||||
"existing frontend: keep its look. Optional sections: none.",
|
||||
"frontend": r"(?=.*\bweb\b)(?=.*html)(?=.*(#0f766e|--color-brand))",
|
||||
"asks": [r"keep|restyle", r"section"],
|
||||
"never_asks": [r"^(?!.*(keep|restyle)).*(colou?r|Tebra Sky|Ember)", r"desktop"],
|
||||
"page_has": ["--accent:#0f766e", "Trebuchet MS"],
|
||||
"existing": "unchanged",
|
||||
},
|
||||
"c-restyle": {
|
||||
"fixture": "c-web-existing-frontend",
|
||||
"prompt": "Build me an RPA dashboard for this project. I can't answer questions while you "
|
||||
"work, so here are my answers to anything the skill asks. Keep or restyle the "
|
||||
"existing frontend: restyle it. Colours: Superbill Ember. Optional sections: none.",
|
||||
"frontend": r"(?=.*\bweb\b)(?=.*html)(?=.*(#0f766e|--color-brand))",
|
||||
"asks": [r"keep|restyle", r"Tebra Sky|Ember", r"section"],
|
||||
"never_asks": [r"desktop"],
|
||||
"page_has": ["--accent:#ff3049"],
|
||||
"existing": "#ff3049", # only token lines may change, and the theme now uses this colour
|
||||
},
|
||||
}
|
||||
# A line a restyle may change: a custom property, a comment, a blank, or a web-font link.
|
||||
TOKEN_LINE = r"^\s*(--[\w-]+\s*:.*|/\*.*\*/|<link[^>]*fonts\.googleapis\.com.*|@import.*fonts\.googleapis\.com.*)?\s*$"
|
||||
|
||||
|
||||
def squash(s):
|
||||
"""Ignore spacing and case when looking for a token in the built page."""
|
||||
return re.sub(r"\s+", "", s).lower()
|
||||
|
||||
|
||||
def changed_lines(src, project):
|
||||
"""Lines removed or added in the fixture's own files."""
|
||||
out = []
|
||||
for f in src.rglob("*"):
|
||||
if f.is_file():
|
||||
new = project / f.relative_to(src)
|
||||
after = new.read_text(encoding="utf-8").splitlines() if new.exists() else []
|
||||
out += [x[1:] for x in difflib.unified_diff(f.read_text(encoding="utf-8").splitlines(), after, lineterm="", n=0)
|
||||
if x[:1] in "+-" and x[:3] not in ("+++", "---")]
|
||||
return out
|
||||
|
||||
|
||||
def main(fixture):
|
||||
cfg = FIXTURES[fixture]
|
||||
work = Path(tempfile.mkdtemp(prefix=f"rpa-eval-{fixture}-"))
|
||||
project = work / "project"
|
||||
shutil.copytree(ROOT / "tests" / "fixtures" / fixture, project)
|
||||
src = ROOT / "tests" / "fixtures" / cfg.get("fixture", fixture)
|
||||
shutil.copytree(src, project)
|
||||
for skill in ROOT.glob("rpa-dashboard-*"):
|
||||
shutil.copytree(skill, project / ".claude" / "skills" / skill.name)
|
||||
|
||||
@@ -61,12 +105,21 @@ def main(fixture):
|
||||
return m[1] if m else ""
|
||||
|
||||
checks = {"frontend reported correctly": bool(re.search(cfg["frontend"], line("FRONTEND"), re.I))}
|
||||
questions = line("QUESTIONS").split("|")
|
||||
for pat in cfg["asks"]:
|
||||
checks[f"asks /{pat}/"] = bool(re.search(pat, line("QUESTIONS"), re.I))
|
||||
checks[f"asks /{pat}/"] = any(re.search(pat, q, re.I) for q in questions)
|
||||
for pat in cfg["never_asks"]:
|
||||
checks[f"never asks /{pat}/"] = not re.search(pat, line("QUESTIONS"), re.I)
|
||||
checks[f"never asks /{pat}/"] = not any(re.search(pat, q, re.I) for q in questions)
|
||||
if "existing" in cfg:
|
||||
changed = changed_lines(src, project)
|
||||
if cfg["existing"] == "unchanged":
|
||||
checks["existing files unchanged"] = not changed
|
||||
else:
|
||||
checks["existing files: only token lines changed"] = bool(changed) and all(re.match(TOKEN_LINE, x) for x in changed)
|
||||
checks[f"existing tokens now use {cfg['existing']}"] = any(cfg["existing"] in x.lower() for x in changed)
|
||||
|
||||
pages = [p for p in project.rglob("*.html") if ".claude" not in p.parts]
|
||||
pages = [p for p in project.rglob("*.html")
|
||||
if ".claude" not in p.parts and not (src / p.relative_to(project)).exists()] # new pages only
|
||||
checks["exactly one page built"] = len(pages) == 1
|
||||
results = ROOT / "tests" / "evals" / "results"
|
||||
results.mkdir(exist_ok=True)
|
||||
@@ -80,6 +133,8 @@ def main(fixture):
|
||||
spec.loader.exec_module(palette)
|
||||
t = palette.derive(cfg["brand"])
|
||||
checks["custom palette applied"] = all(f"--accent:{t[m]['--accent']}" in html for m in t)
|
||||
for needle in cfg.get("page_has", []):
|
||||
checks[f"page has {needle}"] = squash(needle) in squash(html)
|
||||
pc = subprocess.run([sys.executable, "-m", "pytest", str(ROOT / "tests" / "page_check"), "-q"],
|
||||
env={**os.environ, "PAGE_CHECK_HTML": str(pages[0])}, capture_output=True, text=True)
|
||||
checks["page check passes"] = pc.returncode == 0
|
||||
|
||||
Reference in new issue
Block a user