diff --git a/app/static/builder/command-builder-core.js b/app/static/builder/command-builder-core.js
index cc605a60..554b4986 100644
--- a/app/static/builder/command-builder-core.js
+++ b/app/static/builder/command-builder-core.js
@@ -827,7 +827,7 @@
// another page and coming back finds the recipe as it was left. Pure halves:
// the page owns the storage. A draft does not come back when the page was
// opened for something else - a prefill from a run, or a run's own recipe.
- const OPENED_FOR = ['run','like','dataset','model','agent','n_tasks','standard','other'];
+ const OPENED_FOR = ['run','like','saved','dataset','model','agent','n_tasks','standard','other'];
function packDraft(state) {
return JSON.stringify({version: 1, at: new Date().toISOString(), recipe: state.recipe, step: state.step, steps: STEPS.length, first: 'benchmark', tab: state.tab, saved: state.saved || ''});
}
diff --git a/app/static/builder/command-builder.js b/app/static/builder/command-builder.js
index 43154614..9efc2e29 100644
--- a/app/static/builder/command-builder.js
+++ b/app/static/builder/command-builder.js
@@ -113,6 +113,7 @@
let opened = '', savedId = ''; // savedId: the saved recipe this page holds, which a save updates (renames)
if (schema.loadRecipe) { try { recipe = C.fromJSON(schema.loadRecipe); step = REVIEW; opened = 'Opened the recipe of run “' + schema.loadRun + '”. Run gives it a new name.'; } catch (e) { opened = 'This run’s recipe cannot be read: ' + e.message; } }
else if (schema.loadLike) { const o = C.fromJob(schema.loadLike); recipe = o.recipe; step = REVIEW; opened = o.notes.join(' '); }
+ else if (schema.loadSaved) { try { recipe = C.fromJSON(schema.loadSaved.recipe); savedId = schema.loadSaved.id; step = REVIEW; opened = 'Loaded “' + schema.loadSaved.name + '”.'; } catch (e) { opened = 'This saved recipe cannot be read: ' + e.message; } }
// An unsupported draft opens nothing; its rejection is shown as a toast.
else { let d = null; try { d = C.unpackDraft(localStorage.getItem(draftKey), query); } catch {} if (d && d.recipe) { recipe = d.recipe; step = d.step; tab = d.tab; savedId = d.saved; } else if (d && d.gone) opened = d.gone; }
const saveDraft = () => { try { localStorage.setItem(draftKey, C.packDraft({recipe, step, tab, saved: savedId})); } catch {} };
diff --git a/app/static/builder/recipes.css b/app/static/builder/recipes.css
new file mode 100644
index 00000000..a08e2f55
--- /dev/null
+++ b/app/static/builder/recipes.css
@@ -0,0 +1,19 @@
+/* The Recipes page: one row per saved recipe; Info and Delete in one dialog (the Launches page's, runs/launches.css). */
+.rcp-head { justify-content: space-between; align-items: center; }
+.rcp-name { overflow-wrap: anywhere; } /* a name wraps, never cut */
+.rcp-warn { display: flex; align-items: center; gap: 4px; margin-top: 2px; font-size: 12.5px; color: var(--patch_failed_tests); cursor: help; }
+.rcp-warn .ic { width: 14px; height: 14px; }
+.rcp-val { display: block; max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* the whole value is its tooltip */
+#recipes td[data-col="name"] { white-space: normal; }
+dialog.std-how.launch-delete.wide { width: min(56rem, calc(100vw - 32px)); }
+.launch-delete .rcp-problems { list-style: none; padding: 0; margin: 12px 0 0; }
+.rcp-problems li { display: flex; gap: 8px; align-items: baseline; padding: 6px 10px; margin-top: 4px; border-radius: 8px; font-size: 13px;
+ background: color-mix(in srgb, var(--patch_failed_tests) 12%, var(--surface)); }
+.rcp-problems .ic { width: 14px; height: 14px; color: var(--patch_failed_tests); align-self: center; }
+.rcp-step h3 em { font-style: normal; margin-right: 8px; }
+.rcp-row { display: grid; grid-template-columns: minmax(7rem, 12rem) 1fr; gap: 12px; padding: 4px 0; border-top: 1px solid var(--border-soft); }
+.rcp-row small { color: var(--text-dim); }
+.rcp-row span { overflow-wrap: anywhere; }
+.rcp-json { max-height: 22rem; overflow: auto; margin: 4px 0 0; padding: 10px 12px; border: 1px solid var(--border-soft); border-radius: 8px;
+ background: var(--surface-2); font-size: 12px; line-height: 1.5; }
+@media (max-width: 640px) { .rcp-row { grid-template-columns: 1fr; gap: 0; } }
diff --git a/app/static/builder/recipes.js b/app/static/builder/recipes.js
new file mode 100644
index 00000000..500101db
--- /dev/null
+++ b/app/static/builder/recipes.js
@@ -0,0 +1,102 @@
+/* The Recipes page (templates/builder/recipes.html): each saved recipe step by step, and what the builder's own
+ check of a loaded recipe says this Nullius cannot run of it - the recipe core's for a Harbor recipe (fromJSON,
+ validate, providerBlocker), the compile of its Review step for a standard one, done by the server for the page. */
+(function () {
+ 'use strict';
+ const STEPS = ['benchmark', 'runner', 'dataset', 'agent', 'model', 'limits', 'where'];
+ // {rows: [[step, title, value]], problems: [[step, message]]}; a recipe the core cannot read is its one problem.
+ function described(C, raw, compiled) {
+ let r;
+ const benchmark = typeof raw.benchmark === 'string' ? raw.benchmark : '';
+ try { r = C.fromJSON(raw); } catch (e) { return {rows: [], benchmark, problems: [[C.STEP.runner, e.message]]}; }
+ const out = C.isStandard(r) ? compiled || {review: [], errors: []} : {review: C.review(r), errors: C.validate(r).errors};
+ const blocked = C.providerBlocker(r);
+ return {rows: out.review, benchmark, problems: [...out.errors.map(e => [e.step, e.message]), ...(blocked ? [[C.STEP.model, blocked]] : [])]};
+ }
+ // A step's cell: the values of its review rows, in order; with none (a recipe its check stopped early), the benchmark it names.
+ const cell = (C, d, key) => d.rows.length ? d.rows.filter(([s]) => s === C.STEP[key]).map(([, , v]) => v).join(' · ') : key === 'benchmark' ? d.benchmark : '';
+ const said = (C, problems) => problems.map(([s, m]) => C.STEPS[s] + ': ' + m).join('\n');
+ // The first free name of a copy of `name`, among `taken`.
+ function copyName(name, taken) {
+ for (let n = 1; ; n++) { const t = name + (n === 1 ? ' (copy)' : ' (copy ' + n + ')'); if (!taken.includes(t)) return t; }
+ }
+ if (typeof module === 'object' && module.exports) { module.exports = {described, cell, said, copyName, STEPS}; return; }
+
+ const page = JSON.parse(document.getElementById('rcp-data').textContent), schema = page.schema;
+ const C = window.NulliusRecipe(schema), byId = Object.fromEntries(page.recipes.map(x => [x.id, x]));
+ const esc = s => String(s).replace(/[&<>"']/g, c => ({'&': '&', '<': '<', '>': '>', '"': '"', "'": '''})[c]);
+ const notify = (m, error = false) => window.nulliusNotify(m, {error});
+ // A write's notice survives the reload that shows its result.
+ const KEY = 'nullius.recipes.said';
+ const reload = m => { try { sessionStorage.setItem(KEY, m); } catch {} location.reload(); };
+ try { const m = sessionStorage.getItem(KEY); sessionStorage.removeItem(KEY); if (m) notify(m); } catch {}
+ const call = async (url, method, body) => {
+ const res = await nulliusFetch(url, {method, headers: {'Content-Type': 'application/json', 'X-CSRF-Token': schema.csrf}, body: JSON.stringify(body)});
+ const j = await res.json().catch(() => ({}));
+ if (!res.ok || j.ok === false) throw Error(j.error || 'HTTP ' + res.status);
+ return j;
+ };
+
+ // The cells, before the table toolkit reads the rows (tables.js wires them once the page is read).
+ const info = {};
+ for (const tr of document.querySelectorAll('#recipes tbody tr')) {
+ const item = byId[tr.dataset.recipe], d = info[item.id] = described(C, item.recipe, page.compiled[item.id]);
+ for (const key of STEPS) { const span = tr.querySelector(`[data-col="${key}"] .rcp-val`), v = cell(C, d, key); span.textContent = v; span.title = v; }
+ if (d.problems.length) { const w = tr.querySelector('.rcp-warn'); w.hidden = false; w.title = said(C, d.problems); }
+ tr.dataset.search = [item.name, ...STEPS.map(k => cell(C, d, k))].join(' ');
+ }
+
+ const dialog = document.getElementById('rcp-dialog');
+ let opener = null;
+ const show = (html, wide) => { dialog.innerHTML = html; dialog.classList.toggle('wide', wide); dialog.showModal(); };
+ dialog.addEventListener('close', () => opener?.focus());
+ dialog.addEventListener('click', e => { // the backdrop, not the dialog's own padding
+ 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) => `
`;
+ function details(item) {
+ const d = info[item.id], shown = STEPS.map(k => C.STEP[k]);
+ const warn = d.problems.length ? `${d.problems.map(([s, m]) => `- ${esc(C.STEPS[s])} ${esc(m)}
`).join('')}
` : '';
+ const steps = shown.map((s, n) => `0${n + 1}${esc(C.STEPS[s])}
${d.rows.filter(([i]) => i === s).map(([, t, v]) => `${esc(t)}${esc(v)}
`).join('')}`).join('');
+ show(head(item.name, true) + warn + steps + `JSON
${esc(JSON.stringify(item.recipe, null, 2))}`, true);
+ }
+ function ask(item) {
+ show(head('Delete recipe ' + item.name) + ``, false);
+ }
+ function download(item) {
+ const url = URL.createObjectURL(new Blob([JSON.stringify(item.recipe, null, 2) + '\n'], {type: 'application/json'})), a = document.createElement('a');
+ a.href = url; a.download = (item.recipe.name || 'recipe') + '.json'; a.click(); setTimeout(() => URL.revokeObjectURL(url), 1000);
+ }
+ document.addEventListener('click', async e => {
+ const b = e.target.closest('[data-act], [data-close], [data-delete], #rcp-import');
+ if (!b || b.getAttribute('aria-disabled') === 'true') return;
+ const item = byId[b.closest('[data-recipe]')?.dataset.recipe];
+ if (b.dataset.close !== undefined) return dialog.close();
+ if (b.dataset.act === 'info') { opener = b; return details(item); }
+ if (b.dataset.act === 'delete') { opener = b; return ask(item); }
+ if (b.dataset.act === 'export') return download(item);
+ try {
+ if (b.dataset.act === 'duplicate') {
+ const name = copyName(item.name, page.recipes.map(x => x.name));
+ await call('/new-run/recipes', 'POST', {recipe: {...item.recipe, title: name}});
+ reload('Saved “' + name + '”.');
+ } else if (b.dataset.delete) {
+ await call('/new-run/recipes/' + encodeURIComponent(b.dataset.delete), 'DELETE', {});
+ reload('Deleted “' + byId[b.dataset.delete].name + '”.');
+ } else if (b.id === 'rcp-import') document.getElementById('rcp-file').click();
+ } catch (err) { notify((b.dataset.delete ? 'Not deleted: ' : 'Not saved: ') + err.message, true); }
+ });
+ document.getElementById('rcp-file').addEventListener('change', async e => {
+ const file = e.target.files[0];
+ e.target.value = '';
+ if (!file) return;
+ let body;
+ try { body = JSON.parse(await file.text()); } catch { return notify('Not imported: ' + file.name + ' is not JSON.', true); }
+ try {
+ const j = await call('/new-run/recipes/import', 'POST', body), n = j.added.length;
+ const skipped = j.skipped.map(x => '“' + x.name + '”');
+ reload([n ? 'Imported ' + n + ' recipe' + (n > 1 ? 's' : '') + '.' : '', skipped.length ? 'Already saved: ' + skipped.join(', ') + '.' : ''].filter(Boolean).join(' '));
+ } catch (err) { notify(err.message, true); }
+ });
+})();
diff --git a/app/static/style.css b/app/static/style.css
index 0350949b..5e903da3 100644
--- a/app/static/style.css
+++ b/app/static/style.css
@@ -1248,6 +1248,7 @@ input[type=text].invalid:focus { box-shadow: inset 0 0 0 1px var(--bad); }
background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
border-radius: 8px; padding: .65rem .85rem; font-size: .85rem; margin-bottom: 1rem;
}
+.page-title + .alert { margin-top: 1rem; } /* the gap the controls row leaves when a table shows */
.alert .mono { color: var(--text); }
.alert.error {
background: color-mix(in srgb, var(--agent_error) 12%, var(--surface));
diff --git a/app/templates/base.html b/app/templates/base.html
index e55e3bbe..f76cacf0 100644
--- a/app/templates/base.html
+++ b/app/templates/base.html
@@ -55,6 +55,9 @@
+
+
+
@@ -213,6 +216,7 @@
Manage
Workspaces
Launches
+ Recipes
Settings
diff --git a/app/templates/builder/recipes.html b/app/templates/builder/recipes.html
new file mode 100644
index 00000000..93f9ab4b
--- /dev/null
+++ b/app/templates/builder/recipes.html
@@ -0,0 +1,48 @@
+{% from '_tables.html' import table, cell, greyed %}
+{% extends "base.html" %}
+{% block title %}Recipes — Nullius{% endblock %}
+{% block crumb %}/ recipes{% endblock %}
+{% block head %}
+{# its dialog #}
+
+{% endblock %}
+{#- A recipe's row: its step cells and its search are filled by builder/recipes.js. #}
+{% macro recipe_tr(x) %} data-recipe="{{ x.id }}"{% endmacro %}
+
+{% block body %}
+{% set local, why = builder_data.local, builder_data.recipesWhy %}
+Recipes
+
+
+
+{% if recipes %}
+{#- a column per step of the run builder, 01 to 07, by its key in command-builder-core.js (STEP) #}
+{% set cols = [dict(key='name', label='Name', sticky=true, menu=false, width='expand'), dict(key='benchmark', label='Benchmark'), dict(key='runner', label='Runner'),
+ dict(key='dataset', label='Dataset'), dict(key='agent', label='Agent'), dict(key='model', label='Model'), dict(key='limits', label='Limits'),
+ dict(key='where', label='Where'), dict(key='saved', label='Saved', type='num', align='left'), dict(key='actions', label='Actions', blank=true)] %}
+{% call(x, c) table('recipes', cols, recipes, recipe_tr, search='Search by name, benchmark or agent', columns=true, empty='No recipe matches.', noun='recipes') %}
+ {%- if c.key == 'name' %}{% call cell(c, sort=x.name) %}{{ x.name }}
+ Cannot run here{% endcall %}
+ {%- elif c.key == 'saved' %}{% call cell(c, sort=x.saved[:19]|replace('-', '')|replace(':', '')|replace('T', ''), class='mono faint nowrap') %}{{ x.saved[:16]|replace('T', ' ') }}{% endcall %}
+ {%- elif c.key == 'actions' %}{% call cell(c, class='acts-col') %}
+
+
+ {%- if local %}
+ {%- else %}{{ greyed('Duplicate ' ~ x.name, 'Duplicate', why, 'dup-' ~ x.id, icon='copy', class='icon-btn') }}{% endif %}
+
+ {%- if local %}
+ {%- else %}{{ greyed('Delete ' ~ x.name, 'Delete recipe', why, 'del-' ~ x.id) }}{% endif %}
+ {% endcall %}
+ {%- else %}{% call cell(c) %}{% endcall %}
+ {%- endif %}
+{% endcall %}
+{% else %}
+No saved recipe yet.{% if local %}
Build one →{% endif %}
+{% endif %}
+
+
+{% endblock %}
+{% block scripts %}
+
+
+{% endblock %}
diff --git a/app/ui_tests/test_recipes_page.py b/app/ui_tests/test_recipes_page.py
new file mode 100644
index 00000000..5749f8c0
--- /dev/null
+++ b/app/ui_tests/test_recipes_page.py
@@ -0,0 +1,122 @@
+"""The Recipes page (/recipes): the saved recipes as a table, a column per builder step; Import, Duplicate and
+Delete greyed for a browser on another machine; Open in the run builder (/new-run?saved=); and, under Node,
+the warning its script draws from the builder's own check of each recipe."""
+from __future__ import annotations
+
+import json
+import os
+import shutil
+import subprocess
+import tempfile
+import unittest
+from contextlib import ExitStack
+from pathlib import Path
+from unittest.mock import patch
+
+from nullius.recipes import store
+from .test_routes import web
+
+REMOTE = {"REMOTE_ADDR": "10.0.0.2"}
+STATIC = Path(__file__).resolve().parents[1] / "static" / "builder"
+STEPS = ["Benchmark", "Runner", "Dataset", "Agent", "Model", "Limits", "Where"]
+
+
+def recipe(title, name="r", **kw):
+ return dict({"version": 1, "harness": "harbor", "name": name, "title": title}, **kw)
+
+
+class RecipesPage(unittest.TestCase):
+ def setUp(self):
+ self.stack = ExitStack(); self.addCleanup(self.stack.close)
+ self.tmp = tempfile.mkdtemp(prefix="nullius-recipes-"); self.addCleanup(shutil.rmtree, self.tmp, True)
+ self.stack.enter_context(patch.dict(os.environ, {"NULLIUS_HOME": self.tmp}))
+ self.stack.enter_context(patch.dict(web.app.config, TESTING=True))
+ self.client = web.app.test_client()
+
+ def page(self, **kw):
+ r = self.client.get("/recipes", **kw); self.addCleanup(r.close)
+ self.assertEqual(r.status_code, 200)
+ return r.get_data(as_text=True)
+
+ def test_the_page_has_its_link_a_column_per_step_and_a_row_per_recipe(self):
+ html = self.page()
+ self.assertIn('href="/recipes" data-label="Recipes"', html)
+ self.assertIn('No saved recipe yet. Build one', html)
+ self.assertIn("No saved recipe yet.", self.page(environ_base=REMOTE)) # it could not save one
+ self.assertIn('id="rcp-import">