Per-agent ranking: votes, affinity and a taste term; settings are three sub-tabs

Votes on roles and company affinity move to role_votes and agent_companies,
one row per search agent, so two agents rank the same roles differently. The
score gains taste, the cosine to mean(liked) - mean(passed) of the agent's
votes, as newsdesk ranks articles. The API takes agent on roles, votes and
companies and falls back to the default agent, the enabled one with the
lowest id.

Settings become Search agents (a list again, with New and Delete), Sources
(job boards, company boards and runs with the message log, one section per
plugin) and Account. Old paths answer 301 to their section.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-28 12:53:41 +02:00
1 parent 515d2250fc
commit a0772519b3
28 files changed
+1461 -668

No files matched your search

+227
View File
@@ -0,0 +1,227 @@
/* The Search agents page: what Best match on the Roles tab is measured
* against, one agent at a time.
*
* The list is `/api/agents`; the form edits the agent picked from it, New
* clears it, Delete removes it. Votes, liked companies and scores are the
* agent's, so a delete takes them with it, and the confirm says so.
*
* Every request goes through `api()` from app.js, so a failure is one toast
* carrying the server's own sentence.
*/
(function () {
"use strict";
const { api, count } = window;
const $ = (sel, root = document) => root.querySelector(sel);
const DEFAULT_WEIGHTS = { fit: 0.6, recency: 0.2, affinity: 0.2, taste: 0.2 };
/** @type {object[]} every agent, as the server lists them */
let agents = [];
/** @type {object | null} the agent the form edits, null for a new one */
let agent = null;
function byId(rows) {
return [...rows].sort((a, b) => a.id - b.id);
}
// ---------------------------------------------------------------- the list
function onSwitch(row) {
const box = document.createElement("input");
box.type = "checkbox";
box.checked = Boolean(row.enabled);
box.setAttribute("aria-label", `Enable ${row.name}`);
box.addEventListener("change", async () => {
box.disabled = true;
try {
const saved = await api("/api/agents", {
method: "POST", body: Object.assign({}, row, { enabled: box.checked }),
});
Object.assign(row, saved);
} catch (err) {
box.checked = !box.checked;
}
box.disabled = false;
render();
});
return box;
}
function render() {
const body = $("#agents-list");
body.replaceChildren();
for (const row of byId(agents)) {
const div = document.createElement("div");
div.className = "crow";
if (!row.enabled) div.dataset.hidden = "true";
if (agent && agent.id === row.id) div.dataset.current = "true";
const name = document.createElement("span");
name.className = "name";
name.textContent = row.name;
div.appendChild(name);
div.appendChild(onSwitch(row));
const sub = document.createElement("span");
sub.className = "sub";
const w = Object.assign({}, DEFAULT_WEIGHTS, row.weights);
sub.append(`fit ${w.fit} · newness ${w.recency} · companies ${w.affinity} · liked ${w.taste}`, " ");
const edit = document.createElement("button");
edit.type = "button";
edit.className = "linky";
edit.textContent = "Edit";
edit.addEventListener("click", () => fill(row));
const remove = document.createElement("button");
remove.type = "button";
remove.className = "linky";
remove.textContent = "Delete";
remove.addEventListener("click", () => removeAgent(row));
sub.append(edit, " ", remove);
div.appendChild(sub);
body.appendChild(div);
}
$("#agents-count").textContent = agents.length
? count(agents.length, "search agent")
: "No search agents yet. Describe one below.";
}
// ---------------------------------------------------------------- the form
function fill(row) {
agent = row;
const weights = Object.assign({}, DEFAULT_WEIGHTS, row ? row.weights : {});
$("#agent-form-title").textContent = row ? `Edit ${row.name}` : "New agent";
$("#a-name").value = row ? row.name : "";
$("#a-intent").value = row ? row.intent : "";
$("#a-gates").value = JSON.stringify(row ? row.gates : [], null, 2);
$("#a-fit").value = weights.fit;
$("#a-recency").value = weights.recency;
$("#a-affinity").value = weights.affinity;
$("#a-taste").value = weights.taste;
$("#a-delete").hidden = !row;
$("#agent-status").textContent = "";
render();
if (row) $("#agent-form").scrollIntoView({ behavior: "smooth", block: "start" });
}
async function save(event) {
event.preventDefault();
const status = $("#agent-status");
let gates;
try {
gates = JSON.parse($("#a-gates").value || "[]");
} catch (err) {
window.toast.error(`Gates are not valid JSON: ${err.message}`);
return;
}
const body = {
name: $("#a-name").value.trim(),
intent: $("#a-intent").value,
gates,
weights: {
fit: Number($("#a-fit").value),
recency: Number($("#a-recency").value),
affinity: Number($("#a-affinity").value),
taste: Number($("#a-taste").value),
},
// Saving an agent means it is wanted, so a new one starts on; the
// list's checkbox is where an existing one is switched.
enabled: agent ? agent.enabled : true,
};
if (agent) body.id = agent.id;
const button = $("#agent-form button[type=submit]");
button.disabled = true;
let saved;
try {
saved = await api("/api/agents", { method: "POST", body });
await load();
} catch (err) {
status.textContent = "";
button.disabled = false;
return;
}
agent = agents.find((a) => a.id === saved.id) || saved;
$("#agent-form-title").textContent = `Edit ${agent.name}`;
$("#a-delete").hidden = false;
render();
await rescore(status);
button.disabled = false;
}
async function removeAgent(row) {
if (!window.confirm(`Delete ${row.name}? Its votes and liked companies go with it.`)) {
return;
}
try {
await api(`/api/agents/${row.id}`, { method: "DELETE" });
} catch (err) {
return;
}
agents = agents.filter((a) => a.id !== row.id);
if (agent && agent.id === row.id) fill(null);
else render();
}
// Start the `score` job and wait for it, so "Saved and scored" means the
// Roles tab already orders by what was saved.
async function rescore(status) {
status.textContent = "Saved. Scoring…";
let job;
try {
job = await api("/api/jobs", { method: "POST", body: { kind: "score", payload: {} } });
} catch (err) {
status.textContent = "Saved, but scoring did not start.";
return;
}
for (let i = 0; i < 300; i += 1) {
await new Promise((resolve) => setTimeout(resolve, 1000));
let snapshot;
try {
snapshot = await api("/api/jobs");
} catch (err) {
return;
}
const busy = [...snapshot.running, ...snapshot.queued].some((j) => j.id === job.id);
if (busy) continue;
const done = snapshot.recent.find((j) => j.id === job.id);
if (done && done.state !== "done") {
status.textContent = `Saved. Scoring ${done.state}.`;
if (done.error) window.toast.error(`Scoring ${done.state}: ${done.error}`);
return;
}
status.replaceChildren("Saved and scored. ");
const link = document.createElement("a");
link.href = `/?agent=${agent.id}`;
link.textContent = "See the best matches";
status.appendChild(link);
return;
}
status.replaceChildren("Saved. Scoring is still running; ");
const link = document.createElement("a");
link.href = "/settings/sources#runs";
link.textContent = "follow it under Runs";
status.append(link, ".");
}
// -------------------------------------------------------------------- init
async function load() {
agents = await api("/api/agents");
}
document.addEventListener("DOMContentLoaded", async () => {
if (!$("#agents-list")) return;
try {
await load();
} catch (err) {
return;
}
// The default agent, the enabled one with the lowest id, is what the
// Roles tab and the company list fall back to, so it is what opens.
const first = byId(agents).find((a) => a.enabled) || byId(agents)[0] || null;
fill(first);
$("#agent-form").addEventListener("submit", save);
$("#a-new").addEventListener("click", () => fill(null));
$("#a-delete").addEventListener("click", () => agent && removeAgent(agent));
});
})();
+21 -5
View File
@@ -124,6 +124,17 @@ a { color: var(--accent); }
}
.subtabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
/* The jump row under the sub-tabs on Sources: one link per section, since
the page is three sections long. Each section clears the sticky bar when
the anchor lands. */
.jump { display: flex; gap: .25rem .75rem; flex-wrap: wrap; margin: -6px 0 10px; font-size: .9rem; }
.jump a { color: var(--dim); text-decoration: none; }
@media (hover: hover) {
.jump a:hover { color: var(--fg); text-decoration: underline; }
}
section[id] { scroll-margin-top: calc(var(--header-h, 3.5rem) + .5rem); }
.card h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
main {
max-width: 62rem;
margin: 0 auto;
@@ -550,7 +561,7 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
padding: .75rem 1rem;
}
.agent-form h2 { font-size: 1rem; margin: 0; }
.agent-form h2, .agent-form h3 { font-size: 1rem; margin: 0; }
.agent-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; }
.agent-form label.inline { flex-direction: row; align-items: center; gap: .4rem; }
.agent-form input[type="text"], .agent-form textarea, .agent-form input[type="number"] {
@@ -568,7 +579,7 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
.agent-form details[open] summary { margin-bottom: .5rem; }
/* ================================================================ */
/* companies and sources — Settings' Companies and Searches pages, */
/* companies and sources — the Sources page's sections, */
/* static/companies.js and static/sources.js. Package B2's own */
/* section; the rest of the file is not reflowed for it. */
/* ================================================================ */
@@ -576,6 +587,9 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
.section { margin: 1.5rem 0 2rem; }
.section > h2 { margin-bottom: .25rem; }
.source-form { margin-top: 1rem; max-width: none; }
/* The agent select on the filter row: a label beside its box, not above. */
.filters label.inline { display: flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--dim); }
.filters label.inline select { color: var(--fg); }
/* `auto-fit` rather than a fixed count of columns: a row with fewer fields
(Jobindex's Area, say, where Adzuna also needs Country and Place) simply
leaves the boxes it does have at the same width instead of stretching one
@@ -617,6 +631,8 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
gap: .4rem; font-size: .8rem; color: var(--dim);
}
.srow[data-muted="true"], .crow[data-hidden="true"] { opacity: .6; }
/* The agent the form is editing, on the Search agents list. */
.crow[data-current="true"] .name { color: var(--accent); }
.linky {
padding: 0; border: 0; background: none; font-size: .8rem;
@@ -672,9 +688,9 @@ table.list select { padding: .25rem .4rem; }
.top nav a { flex: 1 1 auto; text-align: center; padding: .6rem .4rem; white-space: nowrap; }
.top nav a.icon { flex: 0 0 auto; justify-content: center; padding-inline: .7rem; }
/* Six sub-tabs are too many for one row, and a scrolling strip does not
show that more are off the edge. They wrap, three to a row, as pills
rather than the desktop's underlined row. */
/* Three sub-tabs, one row of pills rather than the desktop's underlined
row; they wrap if a label needs it, since a scrolling strip does not
show that more are off the edge. */
.subtabs { flex-wrap: wrap; border-bottom: none; gap: 6px; }
.subtabs a {
flex: 1 1 30%;
+12 -6
View File
@@ -17,6 +17,10 @@
* `count`, `cell`, `debounce`, and the company list with its affinity control
* (`loadCompanies`, `companies`, `affinityControl`, `setAffinity`). One copy
* each, since two copies of a helper is one of them being fixed.
*
* Affinity is per search agent. The three company helpers take the agent's
* id as an optional last argument and send it along; a caller that passes
* none gets the server's default agent, the enabled one with the lowest id.
*/
(function () {
@@ -106,8 +110,9 @@
Map, refilled in place, so a script holding it sees every reload. */
const companies = new Map();
async function loadCompanies() {
const rows = await api("/api/companies");
async function loadCompanies(agent) {
const query = agent == null ? "" : `?agent=${encodeURIComponent(agent)}`;
const rows = await api(`/api/companies${query}`);
companies.clear();
for (const c of rows) companies.set(c.key, c);
return companies;
@@ -127,7 +132,7 @@
/* `onChange` runs after the server accepted the change, so each page
decides what a change means for it: the role list refetches, since a
hidden company's roles come out of it, and the company list redraws. */
function affinityControl(companyKey, current, onChange) {
function affinityControl(companyKey, current, onChange, agent) {
const span = document.createElement("span");
span.className = "affinity";
span.setAttribute("role", "group");
@@ -142,18 +147,19 @@
button.setAttribute("aria-label", level.label);
button.setAttribute("aria-pressed", String(pressed));
button.addEventListener("click", () =>
setAffinity(companyKey, pressed ? 0 : level.value, onChange));
setAffinity(companyKey, pressed ? 0 : level.value, onChange, agent));
span.appendChild(button);
}
return span;
}
async function setAffinity(companyKey, affinity, onChange) {
async function setAffinity(companyKey, affinity, onChange, agent) {
if (!companyKey) return;
const body = agent == null ? { affinity } : { affinity, agent };
let updated;
try {
updated = await api(`/api/companies/${encodeURIComponent(companyKey)}/affinity`, {
method: "POST", body: { affinity },
method: "POST", body,
});
} catch (err) {
return;
+55 -9
View File
@@ -1,11 +1,17 @@
/* The Companies page: every company, its board, its open roles, its
* affinity, following a new one, and pruning boards with nothing open in a
* region.
/* The Company boards section of Sources: every company, its board, its open
* roles, its affinity, following a new one, and pruning boards with nothing
* open in a region.
*
* The list is app.js's shared company list (`/api/companies`), already
* joined with each company's board subscription — its id and whether it is
* on — so nothing here fetches `/api/sources` as well. The affinity buttons
* are `affinityControl`, the same ones the Roles tab and the read page draw.
*
* Liked and hidden are per search agent, so the `#c-agent` select above the
* list says whose the list shows and whose the buttons set. It opens on the
* server's default, the enabled agent with the lowest id; with no agent at
* all there is nothing to like, and the section says so instead of drawing
* the buttons.
*/
(function () {
"use strict";
@@ -13,6 +19,31 @@
const { api, count, debounce, companies, loadCompanies, affinityControl } = window;
const $ = (sel, root = document) => root.querySelector(sel);
/** @type {object[]} the search agents, by id */
let agents = [];
/** The id in `#c-agent`, or null while there is no agent to pick. */
function agentId() {
const value = $("#c-agent").value;
return value ? Number(value) : null;
}
async function loadAgents() {
agents = (await api("/api/agents")).sort((a, b) => a.id - b.id);
const select = $("#c-agent");
select.replaceChildren();
for (const a of agents) {
const option = document.createElement("option");
option.value = String(a.id);
option.textContent = a.name;
select.appendChild(option);
}
const first = agents.find((a) => a.enabled) || agents[0];
if (first) select.value = String(first.id);
select.closest("label").hidden = !first;
$("#c-no-agent").hidden = Boolean(first);
}
// ---------------------------------------------------------------- the list
function subLine(company) {
@@ -24,7 +55,7 @@
badge.textContent = company.board;
sub.appendChild(badge);
} else {
sub.append("from searches");
sub.append("from job boards");
}
sub.append(` · ${count(company.open_roles, "open role")}`);
return sub;
@@ -88,7 +119,10 @@
row.appendChild(link);
const switchBox = onSwitch(company, render);
if (switchBox) row.appendChild(switchBox);
row.appendChild(affinityControl(company.key, company.affinity, async () => render()));
const agent = agentId();
if (agent != null) {
row.appendChild(affinityControl(company.key, company.affinity, async () => render(), agent));
}
row.appendChild(subLine(company));
body.appendChild(row);
}
@@ -111,7 +145,7 @@
method: "POST",
body: { board, name: $("#b-name").value.trim() },
});
await loadCompanies();
await loadCompanies(agentId());
render();
$("#board-form").reset();
status.textContent = `Following ${result.source.label}: `
@@ -167,7 +201,7 @@
+ `closed ${count(result.roles_closed, "role")}. ${result.boards_left} boards are on.`;
$("#prune-list").replaceChildren();
$("#p-apply").textContent = "Switch off these boards";
await loadCompanies();
await loadCompanies(agentId());
render();
} catch (err) {
$("#p-apply").disabled = false;
@@ -176,15 +210,27 @@
// -------------------------------------------------------------------- init
document.addEventListener("DOMContentLoaded", async () => {
async function switchAgent() {
try {
await loadCompanies();
await loadCompanies(agentId());
} catch (err) {
return;
}
render();
}
document.addEventListener("DOMContentLoaded", async () => {
if (!$("#companies-list")) return;
try {
await loadAgents();
await loadCompanies(agentId());
} catch (err) {
return;
}
render();
$("#c-q").addEventListener("input", debounce(render, 150));
$("#c-filter").addEventListener("change", render);
$("#c-agent").addEventListener("change", switchAgent);
$("#board-form").addEventListener("submit", addBoard);
$("#prune-form").addEventListener("submit", previewPrune);
$("#p-apply").addEventListener("click", applyPrune);
+2 -2
View File
@@ -1,5 +1,5 @@
/* The Pulls page: Pull now on top, one button per remaining kind under
* "Run one stage".
/* The Runs section of Sources: Pull now on top, one button per remaining
* kind under "Run one stage".
*
* The list comes from `/api/jobs/kinds`, which is the registry, so a new
* `@job` in `app/jobs.py` is a new button and this file is not edited --
+4 -4
View File
@@ -1,9 +1,9 @@
/* The Messages tab: the notice log as a table.
/* The message log at the end of Sources' Runs section.
*
* `/api/notices` is the queue's own route (`pipeline/web/jobs.py`) -- the log
* belongs to the queue, the wording belongs to the app, and this page is only
* the reading of it. It redraws on `app:notice` so a failure that happens
* while you are looking at this tab appears without a reload.
* belongs to the queue, the wording belongs to the app, and this is only the
* reading of it. It redraws on `app:notice` so a failure that happens while
* you are looking at the page appears without a reload.
*/
(function () {
-134
View File
@@ -1,134 +0,0 @@
/* The Ranking page: what Best match on the Roles tab is measured against.
*
* The UI shows one ranking. Underneath it is the first enabled search agent,
* the oldest by id, since the `agents` table still holds as many as the CLI
* or the config put there; this page edits that one and never lists, adds or
* deletes. An empty table gets its first agent on the first save.
*
* Every request goes through `api()` from app.js, so a failure is one toast
* carrying the server's own sentence.
*/
(function () {
"use strict";
const { api, count } = window;
const $ = (sel, root = document) => root.querySelector(sel);
/** The name a ranking made here is saved under; the UI never shows it
unless the CLI adds a second one. */
const NEW_NAME = "My ranking";
const DEFAULT_WEIGHTS = { fit: 0.6, recency: 0.2, affinity: 0.2 };
/** @type {object | null} the agent this page edits, null until one is saved */
let agent = null;
/* The first enabled agent, else the first at all: editing it here means it
is wanted, so a save switches it on. */
function pick(agents) {
const byId = [...agents].sort((a, b) => a.id - b.id);
return byId.find((a) => a.enabled) || byId[0] || null;
}
function fill(others) {
$("#a-intent").value = agent ? agent.intent : "";
$("#a-gates").value = JSON.stringify(agent ? agent.gates : [], null, 2);
const weights = agent ? agent.weights : DEFAULT_WEIGHTS;
$("#a-fit").value = weights.fit;
$("#a-recency").value = weights.recency;
$("#a-affinity").value = weights.affinity;
const note = $("#ranking-others");
note.hidden = !(agent && others > 0);
if (!note.hidden) {
note.textContent = `This edits "${agent.name}". ${count(others, "other ranking")} `
+ "can be picked by name in the order menu on Roles.";
}
}
async function save(event) {
event.preventDefault();
const status = $("#ranking-status");
let gates;
try {
gates = JSON.parse($("#a-gates").value || "[]");
} catch (err) {
window.toast.error(`Gates are not valid JSON: ${err.message}`);
return;
}
const body = {
name: agent ? agent.name : NEW_NAME,
intent: $("#a-intent").value,
gates,
weights: {
fit: Number($("#a-fit").value),
recency: Number($("#a-recency").value),
affinity: Number($("#a-affinity").value),
},
enabled: true,
};
if (agent) body.id = agent.id;
const button = $("#ranking-form button[type=submit]");
button.disabled = true;
try {
agent = await api("/api/agents", { method: "POST", body });
} catch (err) {
status.textContent = "";
button.disabled = false;
return;
}
await rescore(status);
button.disabled = false;
}
// Start the `score` job and wait for it, so "Saved and scored" means the
// Roles tab already orders by what was saved.
async function rescore(status) {
status.textContent = "Saved. Scoring…";
let job;
try {
job = await api("/api/jobs", { method: "POST", body: { kind: "score", payload: {} } });
} catch (err) {
status.textContent = "Saved, but scoring did not start.";
return;
}
for (let i = 0; i < 300; i += 1) {
await new Promise((resolve) => setTimeout(resolve, 1000));
let snapshot;
try {
snapshot = await api("/api/jobs");
} catch (err) {
return;
}
const busy = [...snapshot.running, ...snapshot.queued].some((j) => j.id === job.id);
if (busy) continue;
const done = snapshot.recent.find((j) => j.id === job.id);
if (done && done.state !== "done") {
status.textContent = `Saved. Scoring ${done.state}.`;
if (done.error) window.toast.error(`Scoring ${done.state}: ${done.error}`);
return;
}
status.replaceChildren("Saved and scored. ");
const link = document.createElement("a");
link.href = `/?agent=${agent.id}`;
link.textContent = "See the best matches";
status.appendChild(link);
return;
}
status.replaceChildren("Saved. Scoring is still running; ");
const link = document.createElement("a");
link.href = "/settings/pulls";
link.textContent = "follow it under Pulls";
status.append(link, ".");
}
document.addEventListener("DOMContentLoaded", async () => {
let agents;
try {
agents = await api("/api/agents");
} catch (err) {
return;
}
agent = pick(agents);
fill(agents.filter((a) => a.enabled && (!agent || a.id !== agent.id)).length);
$("#ranking-form").addEventListener("submit", save);
});
})();
+9 -7
View File
@@ -1,9 +1,11 @@
/* The Searches page under Settings: saved searches only. Company boards and
* the prune by region moved to Companies, since a board is a company's own,
* not a search's.
/* The Job boards section of Sources: one query on one board per row, on
* Jobindex or Adzuna. The UI says "job board" for what the API and the CLI
* call a search (`/api/searches`, `app searches`); company boards and the
* prune by region are companies.js's section, since a board is a company's
* own, not a query's.
*
* The list comes from `/api/sources`, and every action is a fetch through
* `api()` from app.js, so a refusal (a search that finds nothing) is one
* `api()` from app.js, so a refusal (a query that finds nothing) is one
* toast with the server's own sentence. The catch blocks here only put a
* control back.
*/
@@ -95,8 +97,8 @@
}
const open = data.searches.reduce((sum, s) => sum + s.open_roles, 0);
$("#searches-count").textContent = data.searches.length
? `${count(data.searches.length, "search", "searches")}, ${count(open, "open role")}`
: "No searches yet. Add one below; the starter searches in config.yaml import on the first pull.";
? `${count(data.searches.length, "job board")}, ${count(open, "open role")}`
: "No job boards yet. Add one above; the starter ones in config.yaml import on the first pull.";
}
function showProvider() {
@@ -109,7 +111,7 @@
function fillSearchForm(source) {
const p = (source && source.params) || {};
$("#search-form-title").textContent = source ? `Edit ${source.label}` : "New search";
$("#search-form-title").textContent = source ? `Edit ${source.label}` : "New job board";
$("#s-provider").value = source ? source.provider : "jobindex";
$("#s-name").value = source ? source.label : "";
$("#s-name").readOnly = Boolean(source);