Merge branch 'worktree-agent-a8ed2a864305c4381'

# Conflicts:
#	app/web/api.py
This commit is contained in:
Wolf committed 2026-09-25 22:03:19 +02:00
commit fe83330c82
8 files changed
+418 -319

No files matched your search

+64 -11
View File
@@ -526,13 +526,21 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
.role-main .affinity { margin-left: auto; }
.affinity button {
background: none; border: 1px solid var(--line); border-radius: .3rem;
padding: .1rem .4rem; color: var(--dim); font-size: .85rem; line-height: 1.4;
padding: .1rem .4rem; color: var(--dim); font-size: 1rem; line-height: 1.4;
}
.affinity button[aria-pressed="true"] {
/* One colour per stance, filled rather than tinted so "pressed" reads at a
glance (news's own reasoning for its vote buttons, app.css 1906-1930):
gold for favourite, the app's own accent for like, the error red for
hidden, since hiding a company is the one stance that keeps its roles out
of the list entirely. */
.affinity button[data-value="2"][aria-pressed="true"] {
color: var(--accent-fg); background: var(--warn); border-color: var(--warn);
}
.affinity button[data-value="1"][aria-pressed="true"] {
color: var(--accent-fg); background: var(--accent); border-color: var(--accent);
}
.affinity button[data-value="-1"][aria-pressed="true"] {
background: var(--error); border-color: var(--error);
color: var(--accent-fg); background: var(--error); border-color: var(--error);
}
/* agents */
@@ -567,14 +575,21 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
.agent-form details summary { cursor: pointer; color: var(--dim); font-size: .9rem; }
.agent-form details[open] summary { margin-bottom: .5rem; }
/* sources */
/* ================================================================ */
/* companies and sources — Settings' Companies and Searches pages, */
/* static/companies.js and static/sources.js. Package B2's own */
/* section; the rest of the file is not reflowed for it. */
/* ================================================================ */
.section { margin: 1.5rem 0 2rem; }
.section > h2 { margin-bottom: .25rem; }
.source-form { margin-top: 1rem; }
.form-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.form-row label { flex: 0 1 auto; }
.form-row label.grow { flex: 1 1 14rem; }
.source-form { margin-top: 1rem; max-width: none; }
/* `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
to fill the gap, which is what made the boxes disagree with each other's
width before. */
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .75rem; align-items: start; }
.source-form select {
background: var(--bg); border: 1px solid var(--line);
border-radius: .3rem; padding: .35rem .5rem;
@@ -583,8 +598,46 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
.sample { margin: 0; padding-left: 1.25rem; font-size: .9rem; }
.sample li { margin: .15rem 0; }
.mono { font-family: var(--mono); overflow-wrap: anywhere; }
.row-actions { display: inline-flex; gap: .35rem; }
.row-actions button { padding: .25rem .6rem; }
/* A row of a list that is not a table: Companies and Searches, after news's
`.srow` (app.css 659-665 and 783-787 there). Line one is the name and
whatever switch or controls belong beside it; `.sub`, muted and full width,
wraps onto its own line rather than sharing a column with them, which is
what keeps a long query or board name from crowding the switch at any
width — a table's fixed columns needed a breakpoint to do the same, a grid
with one column spanning the row does not. */
.srows, .crows { display: flex; flex-direction: column; margin: .5rem 0 1.5rem; }
.srow, .crow {
display: grid; grid-template-columns: 1fr auto auto;
align-items: center; column-gap: .6rem; row-gap: .15rem;
padding: .5rem 0; border-bottom: 1px solid var(--line);
}
.srow .name, .crow .name {
grid-column: 1; display: flex; align-items: center; gap: .4rem;
font-size: .96rem; text-decoration: none; color: inherit;
}
.crow .name { font-weight: 600; }
@media (hover: hover) {
.crow .name:hover { text-decoration: underline; }
}
.srow .sub, .crow .sub {
grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center;
gap: .4rem; font-size: .8rem; color: var(--dim);
}
.srow[data-muted="true"], .crow[data-hidden="true"] { opacity: .6; }
.linky {
padding: 0; border: 0; background: none; font-size: .8rem;
color: var(--dim); text-decoration: underline; text-underline-offset: 2px;
}
@media (hover: hover) {
.linky:hover { color: var(--fg); background: none; }
}
/* The prune tool: folded under the list, since switching a board off by
region is an occasional errand and not what the page is for. */
.prune > summary { cursor: pointer; color: var(--dim); font-weight: 600; }
.prune[open] > summary { margin-bottom: .75rem; }
/* applications and companies */
@@ -670,6 +723,6 @@ table.list select { padding: .25rem .4rem; }
.top nav a, .subtabs a { display: inline-flex; align-items: center; justify-content: center; }
.filters input[type="search"], .filters input[type="text"], .filters select,
.agent-form input, .source-form select { min-height: 2.75rem; }
.affinity button { min-width: 2.25rem; }
.affinity button { min-width: 2.75rem; }
.check input { width: 1.25rem; height: 1.25rem; }
}
+16 -10
View File
@@ -113,30 +113,36 @@
return companies;
}
/* Three icon toggles, not four: there is no button for neutral, since
pressing the one that is already pressed is how a company gets back to
it. "Hidden" is the word for -1 everywhere the UI names it, even though
the code and the API keep `mute`/`hide_muted` — a rename in the store
and CLI is a separate, larger change than this control. */
const AFFINITY_LEVELS = [
{ value: -1, label: "Mute" },
{ value: 0, label: "Neutral" },
{ value: 1, label: "Like" },
{ value: 2, label: "Favourite" },
{ value: 2, icon: "★", label: "Favourite" }, // ★
{ value: 1, icon: "▲", label: "Like" }, // ▲
{ value: -1, icon: "⦸", label: "Hidden" }, // ⊘
];
/* The four buttons. `onChange` runs after the server accepted the change,
so each page decides what a change means for it: the role list refetches,
since muting changes which roles come back, and the company table redraws. */
/* `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) {
const span = document.createElement("span");
span.className = "affinity";
span.setAttribute("role", "group");
span.setAttribute("aria-label", "Company affinity");
for (const level of AFFINITY_LEVELS) {
const pressed = level.value === current;
const button = document.createElement("button");
button.type = "button";
button.dataset.value = String(level.value);
button.textContent = level.label[0];
button.textContent = level.icon;
button.title = level.label;
button.setAttribute("aria-label", level.label);
button.setAttribute("aria-pressed", String(level.value === current));
button.addEventListener("click", () => setAffinity(companyKey, level.value, onChange));
button.setAttribute("aria-pressed", String(pressed));
button.addEventListener("click", () =>
setAffinity(companyKey, pressed ? 0 : level.value, onChange));
span.appendChild(button);
}
return span;
+157 -15
View File
@@ -1,42 +1,181 @@
/* The Companies page: every company, its open roles, and its affinity.
/* 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 list is app.js's shared company list, and the affinity buttons are its
* `affinityControl`, the same ones the Roles tab draws on every row. Filtering
* is done here, over the list already loaded.
* 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.
*/
(function () {
"use strict";
const { count, cell, debounce, companies, loadCompanies, affinityControl } = window;
const { api, count, debounce, companies, loadCompanies, affinityControl } = window;
const $ = (sel, root = document) => root.querySelector(sel);
// ---------------------------------------------------------------- the list
function subLine(company) {
const sub = document.createElement("span");
sub.className = "sub";
if (company.board) {
const badge = document.createElement("span");
badge.className = "badge";
badge.textContent = company.board;
sub.appendChild(badge);
} else {
sub.append("from searches");
}
sub.append(` · ${count(company.open_roles, "open role")}`);
return sub;
}
/** The board switch, or nothing for a company known only from a search:
there is no subscription to switch. */
function onSwitch(company, rerender) {
if (company.subscription_id == null) return null;
const box = document.createElement("input");
box.type = "checkbox";
box.checked = Boolean(company.on);
box.setAttribute("aria-label", `Read ${company.name}'s board`);
box.addEventListener("change", async () => {
box.disabled = true;
try {
const result = await api(`/api/sources/${company.subscription_id}/switch`,
{ method: "POST", body: { on: box.checked } });
company.on = result.source.on;
if (!box.checked && result.closed) {
window.toast.info(`${company.name}: ${count(result.closed, "open role")} closed.`);
}
} catch (err) {
box.checked = !box.checked;
}
box.disabled = false;
rerender();
});
return box;
}
function matchesFilter(company, filter) {
switch (filter) {
case "favourite": return company.affinity === 2;
case "liked": return company.affinity === 1;
case "hidden": return company.affinity === -1;
case "on": return company.on === true;
case "off": return company.on === false;
default: return true;
}
}
function render() {
const q = $("#c-q").value.trim().toLowerCase();
const affinity = $("#c-affinity").value;
const filter = $("#c-filter").value;
const rows = [...companies.values()]
.filter((c) => !q || c.name.toLowerCase().includes(q) || c.board.includes(q))
.filter((c) => affinity === "" || String(c.affinity) === affinity)
.filter((c) => matchesFilter(c, filter))
.sort((a, b) => b.open_roles - a.open_roles || a.name.localeCompare(b.name));
const body = $("#companies-list");
body.replaceChildren();
for (const company of rows) {
const tr = document.createElement("tr");
if (company.affinity === -1) tr.classList.add("muted");
const row = document.createElement("div");
row.className = "crow";
if (company.affinity === -1) row.dataset.hidden = "true";
const link = document.createElement("a");
link.className = "name";
link.href = `/?company=${encodeURIComponent(company.name)}`;
link.title = "This company's open roles";
link.textContent = company.name;
cell(tr, "Company", link);
cell(tr, "Board", company.board || "");
cell(tr, "Open roles", String(company.open_roles)).className = "num";
cell(tr, "Affinity", affinityControl(company.key, company.affinity, async () => render()));
body.appendChild(tr);
row.appendChild(link);
const switchBox = onSwitch(company, render);
if (switchBox) row.appendChild(switchBox);
row.appendChild(affinityControl(company.key, company.affinity, async () => render()));
row.appendChild(subLine(company));
body.appendChild(row);
}
const open = rows.reduce((sum, c) => sum + c.open_roles, 0);
$("#companies-count").textContent =
`${count(rows.length, "company", "companies")}, ${count(open, "open role")}`;
}
// -------------------------------------------------------------------- follow
async function addBoard(event) {
event.preventDefault();
const status = $("#board-status");
const button = $("#board-form button[type=submit]");
button.disabled = true;
status.textContent = "Reading the board once before following it…";
const board = `${$("#b-host").value}:${$("#b-slug").value.trim()}`;
try {
const result = await api("/api/boards", {
method: "POST",
body: { board, name: $("#b-name").value.trim() },
});
await loadCompanies();
render();
$("#board-form").reset();
status.textContent = `Following ${result.source.label}: `
+ `${count(result.found, "role")} listed. They arrive with the next pull.`;
} catch (err) {
status.textContent = "";
}
button.disabled = false;
}
// -------------------------------------------------------------------- prune
/** @type {object[]} the boards the last preview named. */
let pruneBoards = [];
async function previewPrune(event) {
event.preventDefault();
const status = $("#prune-status");
const list = $("#prune-list");
const region = $("#p-region").value.trim();
list.replaceChildren();
$("#p-apply").disabled = true;
$("#p-apply").textContent = "Switch off these boards";
status.textContent = "Checking every board…";
try {
const result = await api(`/api/prune?region=${encodeURIComponent(region)}`);
pruneBoards = result.boards;
const roles = pruneBoards.reduce((sum, b) => sum + b.open_roles, 0);
status.textContent = pruneBoards.length
? `${count(pruneBoards.length, "board")} with no open role in ${region}, `
+ `${count(roles, "open role")} between them:`
: `Every board that is on has a role in ${region}.`;
for (const board of pruneBoards) {
const li = document.createElement("li");
li.textContent = `${board.label} (${board.target}), ${count(board.open_roles, "open role")}`;
list.appendChild(li);
}
$("#p-apply").disabled = pruneBoards.length === 0;
$("#p-apply").textContent = `Switch off these ${count(pruneBoards.length, "board")}`;
} catch (err) {
status.textContent = "";
}
}
async function applyPrune() {
const region = $("#p-region").value.trim();
if (!window.confirm(`Switch off ${count(pruneBoards.length, "board")} and close their roles? `
+ "Each can be switched back on in the list above.")) return;
$("#p-apply").disabled = true;
try {
const result = await api("/api/prune", { method: "POST", body: { region } });
$("#prune-status").textContent = `Switched off ${count(result.pruned, "board")}, `
+ `closed ${count(result.roles_closed, "role")}. ${result.boards_left} boards are on.`;
$("#prune-list").replaceChildren();
$("#p-apply").textContent = "Switch off these boards";
await loadCompanies();
render();
} catch (err) {
$("#p-apply").disabled = false;
}
}
// -------------------------------------------------------------------- init
document.addEventListener("DOMContentLoaded", async () => {
try {
await loadCompanies();
@@ -45,6 +184,9 @@
}
render();
$("#c-q").addEventListener("input", debounce(render, 150));
$("#c-affinity").addEventListener("change", render);
$("#c-filter").addEventListener("change", render);
$("#board-form").addEventListener("submit", addBoard);
$("#prune-form").addEventListener("submit", previewPrune);
$("#p-apply").addEventListener("click", applyPrune);
});
})();
+34 -161
View File
@@ -1,21 +1,20 @@
/* The Searches page under Settings: saved searches, and for now the company
* boards and the prune by region as well.
/* 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 template is a shell; the lists come from /api/sources and every action
* is a fetch through `api()` from app.js, so a refusal (a search that finds
* nothing, a board that does not answer) is one toast with the server's own
* sentence. The catch blocks here only put a control back.
* 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
* toast with the server's own sentence. The catch blocks here only put a
* control back.
*/
(function () {
"use strict";
const { api, count, cell, debounce } = window;
const { api, count, debounce } = window;
const $ = (sel, root = document) => root.querySelector(sel);
/** @type {{searches: object[], boards: object[], adzuna_key: boolean}} */
let data = { searches: [], boards: [], adzuna_key: false };
/** @type {object[]} the boards the last prune preview named */
let pruneBoards = [];
/** @type {{searches: object[], adzuna_key: boolean}} */
let data = { searches: [], adzuna_key: false };
/** "DK 120 · EU 4 · unknown 2", the three biggest. */
function countries(source) {
@@ -25,19 +24,11 @@
return shown.join(" · ");
}
function query(source) {
const p = source.params || {};
const where = source.provider === "adzuna"
? [p.country && p.country.toUpperCase(), p.where].filter(Boolean).join(", ")
: (p.area ? $(`#s-area option[value="${p.area}"]`)?.textContent : "All of Denmark");
return `${p.q || ""}${where ? ` — ${where}` : ""}`;
}
function onSwitch(source, rerender) {
const box = document.createElement("input");
box.type = "checkbox";
box.checked = source.on;
box.setAttribute("aria-label", `Pull ${source.label}`);
box.setAttribute("aria-label", `Run ${source.label}`);
box.addEventListener("change", async () => {
box.disabled = true;
try {
@@ -66,35 +57,41 @@
const body = $("#searches-list");
body.replaceChildren();
for (const source of data.searches) {
const tr = document.createElement("tr");
if (!source.on) tr.classList.add("muted");
const row = document.createElement("div");
row.className = "srow";
if (!source.on) row.dataset.muted = "true";
const name = document.createElement("span");
name.textContent = source.label;
name.className = "name";
const label = document.createElement("span");
label.textContent = source.label;
const provider = document.createElement("span");
provider.className = "badge";
provider.textContent = source.provider;
const title = document.createElement("span");
title.append(name, " ", provider);
cell(tr, "Search", title);
cell(tr, "Query", query(source)).className = "mono small";
cell(tr, "Open roles", String(source.open_roles)).className = "num";
cell(tr, "Countries", countries(source)).className = "small";
cell(tr, "On", onSwitch(source, renderSearches));
const actions = document.createElement("span");
actions.className = "row-actions";
name.append(label, provider);
row.appendChild(name);
row.appendChild(onSwitch(source, renderSearches));
const q = (source.params && source.params.q) || "";
const sub = document.createElement("span");
sub.className = "sub";
const parts = [q, `${source.open_roles} open`];
if (source.countries.length) parts.push(countries(source));
sub.append(parts.join(" · "), " ");
const edit = document.createElement("button");
edit.type = "button";
edit.className = "secondary";
edit.className = "linky";
edit.textContent = "Edit";
edit.addEventListener("click", () => fillSearchForm(source));
const remove = document.createElement("button");
remove.type = "button";
remove.className = "secondary";
remove.className = "linky";
remove.textContent = "Remove";
remove.addEventListener("click", () => removeSearch(source));
actions.append(edit, remove);
cell(tr, "", actions);
body.appendChild(tr);
sub.append(edit, " ", remove);
row.appendChild(sub);
body.appendChild(row);
}
const open = data.searches.reduce((sum, s) => sum + s.open_roles, 0);
$("#searches-count").textContent = data.searches.length
@@ -203,123 +200,6 @@
}
}
// ------------------------------------------------------------------ boards
function renderBoards() {
const q = $("#b-q").value.trim().toLowerCase();
const on = $("#b-on").value;
const rows = data.boards
.filter((b) => !q || b.label.toLowerCase().includes(q) || b.target.includes(q))
.filter((b) => !on || (on === "on") === b.on)
.sort((a, b) => Number(b.on) - Number(a.on) || b.open_roles - a.open_roles
|| a.label.localeCompare(b.label));
const body = $("#boards-list");
body.replaceChildren();
for (const board of rows) {
const tr = document.createElement("tr");
if (!board.on) tr.classList.add("muted");
const link = document.createElement("a");
link.href = `/?company=${encodeURIComponent(board.label)}`;
link.title = "This company's open roles";
link.textContent = board.label;
cell(tr, "Company", link);
cell(tr, "Board", board.target).className = "mono small";
cell(tr, "Open roles", String(board.open_roles)).className = "num";
cell(tr, "Countries", countries(board)).className = "small";
cell(tr, "On", onSwitch(board, renderBoards));
body.appendChild(tr);
}
const onCount = data.boards.filter((b) => b.on).length;
$("#boards-count").textContent =
`${count(data.boards.length, "board")}, ${onCount} on. Showing ${rows.length}.`;
}
async function addBoard(event) {
event.preventDefault();
const status = $("#board-status");
const button = $("#board-form button[type=submit]");
button.disabled = true;
status.textContent = "Reading the board once before following it…";
try {
const result = await api("/api/boards", {
method: "POST",
body: { board: $("#b-board").value.trim(), name: $("#b-name").value.trim() },
});
data.boards.push(result.source);
renderBoards();
$("#board-form").reset();
status.textContent = `Following ${result.source.label}: `
+ `${count(result.found, "role")} listed. They arrive with the next pull.`;
} catch (err) {
status.textContent = "";
}
button.disabled = false;
}
// ------------------------------------------------------------------- prune
async function previewPrune(event) {
event.preventDefault();
const status = $("#prune-status");
const list = $("#prune-list");
const region = $("#p-region").value.trim();
list.replaceChildren();
$("#p-apply").disabled = true;
status.textContent = "Checking every board…";
try {
const result = await api(`/api/prune?region=${encodeURIComponent(region)}`);
pruneBoards = result.boards;
const roles = pruneBoards.reduce((sum, b) => sum + b.open_roles, 0);
status.textContent = pruneBoards.length
? `${count(pruneBoards.length, "board")} with no open role in ${region}, `
+ `${count(roles, "open role")} between them:`
: `Every board that is on has a role in ${region}.`;
for (const board of pruneBoards) {
const li = document.createElement("li");
li.textContent = `${board.label} (${board.target}), ${count(board.open_roles, "open role")}`;
list.appendChild(li);
}
$("#p-apply").disabled = pruneBoards.length === 0;
} catch (err) {
status.textContent = "";
}
}
async function applyPrune() {
const region = $("#p-region").value.trim();
if (!window.confirm(`Switch off ${count(pruneBoards.length, "board")} and close their roles? `
+ "Each can be switched back on in the list above.")) return;
$("#p-apply").disabled = true;
try {
const result = await api("/api/prune", { method: "POST", body: { region } });
$("#prune-status").textContent = `Switched off ${count(result.pruned, "board")}, `
+ `closed ${count(result.roles_closed, "role")}. ${result.boards_left} boards are on.`;
$("#prune-list").replaceChildren();
await load();
renderBoards();
} catch (err) {
$("#p-apply").disabled = false;
}
}
// -------------------------------------------------------------------- pull
async function pullNow() {
const button = $("#pull-now");
button.disabled = true;
try {
await api("/api/jobs", { method: "POST", body: { kind: "pull", payload: {} } });
$("#pull-status").replaceChildren("Pull started. ");
const link = document.createElement("a");
link.href = "/settings/pulls";
link.textContent = "Follow it under Pulls";
$("#pull-status").appendChild(link);
} catch (err) {
/* already toasted */
}
button.disabled = false;
}
// -------------------------------------------------------------------- init
document.addEventListener("DOMContentLoaded", async () => {
@@ -330,17 +210,10 @@
return;
}
renderSearches();
renderBoards();
fillSearchForm(null);
$("#s-provider").addEventListener("change", showProvider);
$("#s-try").addEventListener("click", trySearch);
$("#search-form").addEventListener("submit", saveSearch);
$("#s-new").addEventListener("click", () => fillSearchForm(null));
$("#b-q").addEventListener("input", debounce(renderBoards, 150));
$("#b-on").addEventListener("change", renderBoards);
$("#board-form").addEventListener("submit", addBoard);
$("#prune-form").addEventListener("submit", previewPrune);
$("#p-apply").addEventListener("click", applyPrune);
$("#pull-now").addEventListener("click", pullNow);
});
})();