diff --git a/.claude/rules/ui.md b/.claude/rules/ui.md index b968af0b..403f9450 100644 --- a/.claude/rules/ui.md +++ b/.claude/rules/ui.md @@ -48,6 +48,8 @@ also supports `--only KEY` for a focused benchmark check. `app/static/disclosures.js`; navigation groups use the same animation. Respect reduced motion and keyboard activation. Filter menus and popovers are separate. - **One icon, one meaning.** A new kind of thing gets its own icon, never a - neighbour's. + neighbour's. Icons are symbols of `app/templates/_icons.svg`, drawn on its + 24 grid without their own stroke or fill, and used with + ``. A page draws no icon of its own. - Catalogue Add actions share one dialog with the entry type preselected from the page. Keep generated prompts short and refer to import skills instead of duplicating their instructions. diff --git a/AGENTS.md b/AGENTS.md index addc492a..57779619 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -90,6 +90,7 @@ and its resources. builder's JavaScript, which owns the generated recipes. `app/templates/_tables.html` and `app/static/tables.js` are the table toolkit: one column list builds a table's headers, cells and controls. `app/templates/_cards.html` lays the same field list out as cards, one slot per field. + `app/templates/_icons.svg` is the icon sprite, checked by `app/tests/test_icons.py`. - `app/tests/`, `app/ui_tests/` — the backend suite and the route suite. Beside the backend tests sit scripts run by hand: `app/tests/field_contract.py`, which refreshes the `field_contract.json` the diff --git a/app/static/builder/command-builder.js b/app/static/builder/command-builder.js index f6110117..8a69b81f 100644 --- a/app/static/builder/command-builder.js +++ b/app/static/builder/command-builder.js @@ -378,10 +378,9 @@ // Harbor's own mark where Harbor fetches the tasks; a plain icon where no one's mark belongs. Square tiles, so // a mark is never read as a second radio button. const HARBOR_MARK = ''; - const iconTile = d => ``; + const iconTile = name => ``; const SOURCE_MARK = { hub: HARBOR_MARK, registry: HARBOR_MARK, - local: iconTile('M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z'), - generate: iconTile('M15 4V2M15 16v-2M8 9h2M20 9h2M17.8 11.8 19 13M15 9h.01M17.8 6.2 19 5M3 21l9-9M12.2 6.2 11 5') }; + local: iconTile('folder'), generate: iconTile('wand') }; const SOURCE_HINT = { hub: 'Harbor fetches the tasks when the run starts.', registry: 'Harbor fetches the tasks when the run starts.', local: 'Task folders already on disk. A run on a host is sent them.', generate: "Built first with the benchmark's own generator, into a folder you name." }; const segmented = (name, label, segments) => `
${segments}
`; @@ -626,7 +625,7 @@ + (t.meta || t.foot ? `${t.meta ? `${esc(t.meta)}` : ''}${t.foot || ''}` : '') + ''; // a machine to run on: this one or a host, its connection state filled in by Test connection const icon = name => ``; - const machineTile = (attr, v, t, sub, on) => tile({attr, key: v, on, mark: icon(v === 'local' ? 'machine' : 'network'), title: t, tip: sub, + const machineTile = (attr, v, t, sub, on) => tile({attr, key: v, on, mark: v === 'local' ? icon('machine') : icon('network'), title: t, tip: sub, foot: v !== 'local' ? `` : ''}); // The grids drawn by the server and run by the card toolkit (tables.js): the Benchmark step's (/new-run/benchmarks, // one choice) and the standard's Agent step's for its benchmark (/new-run/agents, from the Agents page's entries). diff --git a/app/static/builder/recipes.js b/app/static/builder/recipes.js index 500101db..08f3eeb2 100644 --- a/app/static/builder/recipes.js +++ b/app/static/builder/recipes.js @@ -54,7 +54,7 @@ const r = dialog.getBoundingClientRect(); if (e.target === dialog && (e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom)) dialog.close(); }); - const head = (t, x) => `

${esc(t)}

${x ? '' : ''}
`; + const head = (t, x) => `

${esc(t)}

${x ? '' : ''}
`; function details(item) { const d = info[item.id], shown = STEPS.map(k => C.STEP[k]); const warn = d.problems.length ? `` : ''; diff --git a/app/static/catalogue/catalogue.css b/app/static/catalogue/catalogue.css index 4793c013..d64a1009 100644 --- a/app/static/catalogue/catalogue.css +++ b/app/static/catalogue/catalogue.css @@ -344,7 +344,6 @@ dialog.std-how::backdrop { background: rgba(0, 0, 0, .45); } .std-how-x { flex: none; width: 40px; height: 40px; display: grid; place-items: center; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--text-dim); cursor: pointer; } .std-how-x:hover { color: var(--text); border-color: var(--text-dim); } .std-how-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } -.std-how-x svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; } /* The Add a benchmark dialog, by hand: the three routes, each its bubble, what it is and where to start. */ .std-routes { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; } .std-routes li { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 14px; align-items: start; padding: 14px; border: 1px solid var(--border-soft); border-radius: 10px; } diff --git a/app/static/style.css b/app/static/style.css index 7bf7d7bf..eaaded6b 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -1068,7 +1068,7 @@ tr.control-row td { color: var(--text-dim); } .attempt-tab:hover { color: var(--text); border-color: var(--text-faint); } .attempt-tab[aria-current] { color: var(--text); background: var(--accent-soft); border-color: var(--accent); font-weight: 600; } .attempt-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } -.attempt-retried { width: 12px; height: 12px; margin-left: -.15rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; } +.attempt-retried { width: 12px; height: 12px; margin-left: -.15rem; flex: none; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; } /* an attempt's tries, when its runner kept the ones before its last: tabs of their own under the attempt's, underlined, the last the one that counts */ .try-tabs { display: flex; flex-wrap: wrap; gap: 0 1.2rem; width: fit-content; max-width: 100%; margin-top: .6rem; padding-right: .4rem; border-bottom: 1px solid var(--border); } diff --git a/app/templates/_icons.svg b/app/templates/_icons.svg new file mode 100644 index 00000000..adf75c87 --- /dev/null +++ b/app/templates/_icons.svg @@ -0,0 +1,77 @@ +{#- The interface's icons, included by base.html: one symbol each, referenced by . + Hand-drawn on a 24-grid, stroke only, so they take the item's colour and weight (`.ic` in style.css). #} + diff --git a/app/templates/base.html b/app/templates/base.html index 77df93e9..aaa24685 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -37,75 +37,7 @@ -{# ---- icons: one symbol each, referenced by . Hand-drawn on a 24-grid, - stroke only, so they take the item's colour and weight. ---- #} - +{% include "_icons.svg" %}
{% set ep = request.endpoint or '' %} diff --git a/app/templates/catalogue/add_dialog.html b/app/templates/catalogue/add_dialog.html index 5ff1f21b..e7f59911 100644 --- a/app/templates/catalogue/add_dialog.html +++ b/app/templates/catalogue/add_dialog.html @@ -3,7 +3,7 @@ hand: what the caller puts in. docs/standard.md, "Import by hand" and "With an assistant". -#} {% macro add_dialog(a, prompts, kind) -%} -

Add to catalogue

+

Add to catalogue

diff --git a/app/templates/settings/custom_keys.html b/app/templates/settings/custom_keys.html index da5e6095..849b0e23 100644 --- a/app/templates/settings/custom_keys.html +++ b/app/templates/settings/custom_keys.html @@ -1,6 +1,6 @@ {% macro key_summary(name, state, editor) %}
- +

{{ name }}

{{ {'saved': 'Saved', 'missing': 'Not set', 'expired': 'Expired'}[state] }} diff --git a/app/templates/traces/_attempts.html b/app/templates/traces/_attempts.html index a35aaee6..cd804eae 100644 --- a/app/templates/traces/_attempts.html +++ b/app/templates/traces/_attempts.html @@ -10,7 +10,7 @@ {{ ('Attempt ' if attempts.n <= 4 else '') ~ loop.index }} - {%- if a.n_retries %}{% endif %} + {%- if a.n_retries %}{% endif %} {%- endfor %} All attempts diff --git a/app/tests/test_icons.py b/app/tests/test_icons.py new file mode 100644 index 00000000..db47765e --- /dev/null +++ b/app/tests/test_icons.py @@ -0,0 +1,95 @@ +"""Every icon a page names is a symbol of the sprite, app/templates/_icons.svg, drawn the sprite's way.""" +from __future__ import annotations + +import re +import unittest +import xml.etree.ElementTree as ET +from pathlib import Path + +APP = Path(__file__).resolve().parent.parent +SPRITE = APP / "templates" / "_icons.svg" +SOURCES = [p for p in [*(APP / "templates").rglob("*"), *(APP / "static").rglob("*")] + if p.suffix in (".html", ".js", ".css") and p != SPRITE] + [*(APP / "web").glob("*.py"), *(APP / "nullius").rglob("*.py")] +# Symbols drawn their own way, each with its reason. +STYLE_EXCEPTIONS: dict[str, str] = {} + +ICON_KWARG = ("templates/**/*.html", r"\bicon=(?!true\b|false\b)([^,)\s]+)") # card fields, greyed() +# Each place that builds a symbol id from a value: (file, the expression after "#i-") -> where its values are +# written, as (files, pattern, inner pattern). A pattern captures an argument as written; it must be a quoted name. +SINKS = { + ("templates/base.html", "icon"): [("templates/base.html", r"for kind, label, list_ep, entry_ep, icon in \[(.*?)\] %\}", r",\s*([^,()]+)\)")], + ("templates/_cards.html", "f.icon"): [ICON_KWARG], + ("templates/_tables.html", "key"): [("templates/_tables.html", r"for key, name in \((.*?)\) %\}", r"\(([^,()]+),")], + ("templates/_tables.html", "c.filter_icon"): [("templates/**/*.html", r"\bfilter_icon=([^,)\s]+)")], + ("templates/_tables.html", "icon"): [ICON_KWARG], + ("templates/runs/launches.html", "icon[state]"): [("templates/runs/launches.html", r"set icon = \{(.*?)\} %\}", r":\s*([^,}]+)")], + ("templates/settings/settings.html", "icon"): [ + ("templates/settings/settings.html", r"(? str: + return path.read_text(encoding="utf-8") + + +def sprite() -> ET.Element: + return ET.fromstring(re.sub(r"\{#.*?#\}", "", text(SPRITE), flags=re.S)) + + +def symbols() -> list[ET.Element]: + return sprite().findall("./defs/symbol") + + +class Icons(unittest.TestCase): + names = frozenset(s.get("id", "").removeprefix("i-") for s in symbols()) + + def assertKnown(self, name: str, where: str): + self.assertIn(name, self.names, f"{where}: no symbol i-{name} in {SPRITE.name}") + + def test_every_literal_reference_is_a_symbol(self): + for path in SOURCES: + for name in re.findall(r"#i-([a-z0-9]+(?:-[a-z0-9]+)*)", text(path)): + self.assertKnown(name, str(path.relative_to(APP))) + + def test_every_name_passed_as_data_is_a_symbol(self): + seen = set() + for path in SOURCES: + where = path.relative_to(APP).as_posix() + for expr in re.findall(r"#i-(?:\{\{\s*(.*?)\s*\}\}|\$\{(.*?)\}|(['\"`]))", text(path)): + sink = (where, next(e for e in expr if e)) + self.assertIn(sink, SINKS, f"{where}: a symbol id built from {sink[1]!r}: list where its values come from in SINKS") + seen.add(sink) + self.assertEqual(seen, set(SINKS), "a sink in SINKS is no longer in the code") + for sink, sites in SINKS.items(): + for files, pattern, *inner in sites: + written = [arg for path in APP.glob(files) for m in re.finditer(pattern, text(path), re.S) + for arg in (re.findall(inner[0], m.group(1)) if inner else [m.group(1)])] + self.assertTrue(written, f"{sink}: {pattern!r} finds nothing") + for arg in written: + literal = re.fullmatch(r"\s*(['\"])([a-z0-9-]+)\1\s*", arg) + self.assertTrue(literal, f"{sink}: cannot resolve {arg.strip()!r} to an icon name") + self.assertKnown(literal.group(2), f"{sink[0]} via {files}") + for path in [*(APP / "web").glob("*.py"), *(APP / "nullius").rglob("*.py")]: # bare names built in Python + for name in re.findall(r"""['"](?:filter_)?icon['"]\s*:\s*['"]([a-z0-9-]+)['"]|\b(?:filter_)?icon=['"]([a-z0-9-]+)['"]""", text(path)): + self.assertKnown(next(n for n in name if n), str(path.relative_to(APP))) + + def test_symbols_take_their_style_from_the_page(self): + for symbol in symbols(): + name = symbol.get("id") + if name in STYLE_EXCEPTIONS: + continue + self.assertEqual(symbol.get("viewBox"), "0 0 24 24", name) + for part in symbol.iter(): + self.assertFalse({"stroke", "stroke-width", "fill"} & set(part.attrib), f"{name}: {part.attrib}") + + def test_symbol_ids_are_unique(self): + ids = [s.get("id") for s in symbols()] + self.assertEqual(sorted(i for i in set(ids) if ids.count(i) > 1), []) + self.assertTrue(all(i and i.startswith("i-") for i in ids), ids) + + +if __name__ == "__main__": + unittest.main() diff --git a/pyproject.toml b/pyproject.toml index 712019be..dd09b371 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,4 +56,4 @@ dependencies = {file = ["app/requirements.txt"]} "nullius.catalogue" = ["agents/*/*.json", "agents/*/*.py", "agents/*/*.toml", "agents/*/*.yaml", "benchmarks/*/env/*", "benchmarks/*/*.json", "benchmarks/*/*.py", "benchmarks/*/*.yml", "benchmarks/*/startup/*.py", "capabilities/*/*.json", "capabilities/*/*.py"] "nullius.standard" = ["kits/*/*.json", "kits/*/*.py", "kits/*/*.Dockerfile", "kits/*/*.txt"] "nullius.judge" = ["floors.json"] -_nullius_app = ["templates/**/*.html", "static/**/*.css", "static/**/*.js", "static/**/*.svg", "static/**/*.png", "static/**/*.json", "static/**/*.woff2", "static/**/*.ttf", "static/**/*.txt", "static/**/*.md", "requirements.txt", ".env.example"] +_nullius_app = ["templates/**/*.html", "templates/*.svg", "static/**/*.css", "static/**/*.js", "static/**/*.svg", "static/**/*.png", "static/**/*.json", "static/**/*.woff2", "static/**/*.ttf", "static/**/*.txt", "static/**/*.md", "requirements.txt", ".env.example"]