From 593c351037486444b792af0a53df85a3feac7bb7 Mon Sep 17 00:00:00 2001 From: Wolf Date: Wed, 30 Sep 2026 15:23:04 +0200 Subject: [PATCH 1/4] Add remote.js: the remote badge words, the picks of the remote_from line and how gates share out between Where and Other rules, with tests Co-Authored-By: Claude Opus 5.5 --- app/static/remote.js | 92 ++++++++++++++++++++++++++++++++ tests/js/remote.test.mjs | 110 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 app/static/remote.js create mode 100644 tests/js/remote.test.mjs diff --git a/app/static/remote.js b/app/static/remote.js new file mode 100644 index 0000000..8b15c87 --- /dev/null +++ b/app/static/remote.js @@ -0,0 +1,92 @@ +/* Where a remote role may be worked from, as the pages say it: the words of + * the badge, the picks of the agent's "Remote, open to someone in" chips, and + * how an agent's gates share out between the Where block and Other rules. No + * DOM in it, so `tests/js/remote.test.mjs` can walk it without a browser. + * + * The area is a place token in three spellings, one per layer: `remote:` on the Roles rail and in the address, `` in a + * `remote_from` gate, and a label on a row (`remote_where`). `anywhere` is + * the one place that is no gazetteer town, region or country. + */ +(function () { + "use strict"; + + const ANYWHERE = "anywhere"; + + /** The badge of a row and the reader: "remote · Europe", "remote · anywhere", + "remote · Denmark" from `remote_where`, "remote" alone when the area is + not stated, and the other words (hybrid, onsite) as they are. */ + function remoteBadge(role) { + const word = role && role.remote; + if (!word) return ""; + const where = word === "remote" ? String(role.remote_where || "").trim() : ""; + return where ? `${word} · ${where}` : word; + } + + /** A `/api/suggest/places` answer as the value of a `remote_from` gate, or + null when the Where block does not offer it: countries, regions and + Anywhere. A town, or a remote token that is not Anywhere (the block's + own country pick is the plain one), is left out. */ + function fromSuggestion(s) { + const token = String(s.token || ""); + if (token === `remote:${ANYWHERE}`) return ANYWHERE; + if (token.startsWith("country:") || token.startsWith("region:")) return token; + return null; + } + + /** The words a person can type for Anywhere, which the suggestions may or + may not carry. */ + function offersAnywhere(q) { + const text = String(q).trim().toLowerCase(); + return text.length > 0 && ["anywhere", "worldwide"].some((w) => w.startsWith(text)); + } + + /** The chip label of a gate value when the server has not said it yet. */ + function fallbackLabel(value, countryName) { + if (value === ANYWHERE) return "Anywhere"; + if (value === "country:EU") return "Europe"; + if (value.startsWith("country:")) return countryName(value.slice(8)); + return value.slice(value.indexOf(":") + 1); + } + + /** "remote from Denmark, Sweden or Germany", "remote from anywhere". */ + function remoteSentence(values, label) { + const names = values.map((v) => (v === ANYWHERE ? "anywhere" : label(v))); + const list = names.length < 2 ? names.join("") + : `${names.slice(0, -1).join(", ")} or ${names[names.length - 1]}`; + return `remote from ${list}`; + } + + /** Share out an agent's gates between the Where block and Other rules. Each + Where line takes the first gate it can say whole; the rest are rows. A + must or one-of gate with a weight other than the default stays a row, + since Where would drop it. The remote line is a `remote_from` one-of, or + the older one-of on `remote: [remote]`, which reads as remote from + Anywhere; both save as `remote_from`. Every require gate on country is a + row, "within Europe" among them: it holds for every role and not only + the remote ones, so the block does not fold it into the remote line. */ + function distribute(gates) { + const where = { countries: null, places: null, remote: null, hybrid: null }; + const rest = []; + const plain = (g) => g.weight === undefined || g.weight === 1; + const only = (g, value) => g.values.length === 1 && g.values[0] === value; + let older = null; + for (const g of gates) { + if (g.field === "country" && g.mode === "any" && plain(g) && !where.countries) where.countries = g; + else if (g.field === "place" && g.mode === "any" && plain(g) && !where.places) where.places = g; + else if (g.field === "remote_from" && g.mode === "any" && plain(g) && !where.remote) { + where.remote = { values: g.values.map(String) }; + } else if (g.field === "remote" && g.mode === "any" && plain(g) && only(g, "remote") && !older) { + older = g; + } else if (g.field === "remote" && g.mode === "prefer" && only(g, "hybrid") && !where.hybrid) where.hybrid = g; + else rest.push(g); + } + if (older) { + if (where.remote) rest.push(older); + else where.remote = { values: [ANYWHERE] }; + } + return { where, rest }; + } + + window.remoteHelpers = { ANYWHERE, remoteBadge, fromSuggestion, offersAnywhere, fallbackLabel, remoteSentence, distribute }; +})(); diff --git a/tests/js/remote.test.mjs b/tests/js/remote.test.mjs new file mode 100644 index 0000000..1cde1e9 --- /dev/null +++ b/tests/js/remote.test.mjs @@ -0,0 +1,110 @@ +// static/remote.js without a browser: the badge, the suggestions the agent's +// remote line offers, and how gates share out between Where and Other rules. +// +// node --test tests/js/*.test.mjs + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import vm from "node:vm"; + +const window = {}; +Object.assign(globalThis, { window }); +vm.runInThisContext(readFileSync(new URL("../../app/static/remote.js", import.meta.url), "utf8")); +const rh = window.remoteHelpers; + +const name = (code) => ({ DK: "Denmark", SE: "Sweden", DE: "Germany" })[code] || code; +const label = (v) => rh.fallbackLabel(v, name); + +test("the badge says the area after remote, and remote alone when it is not stated", () => { + assert.equal(rh.remoteBadge({ remote: "remote", remote_where: "Europe" }), "remote · Europe"); + assert.equal(rh.remoteBadge({ remote: "remote", remote_where: "anywhere" }), "remote · anywhere"); + assert.equal(rh.remoteBadge({ remote: "remote", remote_where: "United States, Canada" }), "remote · United States, Canada"); + assert.equal(rh.remoteBadge({ remote: "remote", remote_where: "" }), "remote"); + assert.equal(rh.remoteBadge({ remote: "remote" }), "remote"); +}); + +test("the badge leaves the other words as they are, and a role with none blank", () => { + assert.equal(rh.remoteBadge({ remote: "hybrid", remote_where: "Europe" }), "hybrid"); + assert.equal(rh.remoteBadge({ remote: "onsite", remote_where: "" }), "onsite"); + assert.equal(rh.remoteBadge({ remote: "" }), ""); + assert.equal(rh.remoteBadge(null), ""); +}); + +test("a suggestion is offered to the remote line as a country, a region or Anywhere", () => { + assert.equal(rh.fromSuggestion({ token: "country:DK", kind: "country" }), "country:DK"); + assert.equal(rh.fromSuggestion({ token: "country:EU", kind: "country" }), "country:EU"); + assert.equal(rh.fromSuggestion({ token: "region:oresund", kind: "region" }), "region:oresund"); + assert.equal(rh.fromSuggestion({ token: "remote:anywhere", kind: "remote" }), "anywhere"); + assert.equal(rh.fromSuggestion({ token: "remote:country:DK", kind: "remote" }), null); + assert.equal(rh.fromSuggestion({ token: "place:1", kind: "place" }), null); +}); + +test("Anywhere is offered for the words that start it", () => { + assert.equal(rh.offersAnywhere("any"), true); + assert.equal(rh.offersAnywhere(" World"), true); + assert.equal(rh.offersAnywhere("den"), false); + assert.equal(rh.offersAnywhere(""), false); +}); + +test("a value has a label before the server has said it", () => { + assert.equal(label("anywhere"), "Anywhere"); + assert.equal(label("country:DK"), "Denmark"); + assert.equal(label("country:EU"), "Europe"); + assert.equal(label("region:oresund"), "oresund"); +}); + +test("the sentence lists the areas, and says anywhere in lower case", () => { + assert.equal(rh.remoteSentence(["country:DK", "country:SE", "country:DE"], label), "remote from Denmark, Sweden or Germany"); + assert.equal(rh.remoteSentence(["anywhere"], label), "remote from anywhere"); + assert.equal(rh.remoteSentence(["country:DK"], label), "remote from Denmark"); +}); + +// ------------------------------------------------------------- distribute + +const older = { field: "remote", values: ["remote"], mode: "any" }; +const from = (...values) => ({ field: "remote_from", values, mode: "any" }); +const hybrid = { field: "remote", values: ["hybrid"], mode: "prefer", weight: 0.05 }; +const europe = { field: "country", values: ["DK", "SE", "EU"], mode: "require" }; + +test("no remote gate: the remote line is empty", () => { + const { where, rest } = rh.distribute([{ field: "country", values: ["DK"], mode: "any" }, hybrid]); + assert.equal(where.remote, null); + assert.equal(where.hybrid, hybrid); + assert.deepEqual(rest, []); +}); + +test("a remote_from gate loads into the remote line", () => { + const { where, rest } = rh.distribute([from("country:DK", "anywhere")]); + assert.deepEqual(where.remote, { values: ["country:DK", "anywhere"] }); + assert.deepEqual(rest, []); +}); + +test("the older remote gate loads as remote from Anywhere", () => { + const { where, rest } = rh.distribute([older]); + assert.deepEqual(where.remote, { values: ["anywhere"] }); + assert.deepEqual(rest, []); +}); + +test("a remote_from gate wins over the older one, which stays a row", () => { + for (const gates of [[older, from("country:DK")], [from("country:DK"), older]]) { + const { where, rest } = rh.distribute(gates); + assert.deepEqual(where.remote, { values: ["country:DK"] }); + assert.deepEqual(rest, [older]); + } +}); + +test("the within Europe must is a row, kept whole", () => { + const { where, rest } = rh.distribute([europe, older]); + assert.deepEqual(where.remote, { values: ["anywhere"] }); + assert.deepEqual(rest, [europe]); +}); + +test("a second remote_from gate, a weighted one or a must stays a row", () => { + const second = from("country:SE"); + const weighted = { ...from("country:DE"), weight: 2 }; + const must = { field: "remote_from", values: ["country:DK"], mode: "require" }; + const { where, rest } = rh.distribute([from("country:DK"), second, weighted, must]); + assert.deepEqual(where.remote, { values: ["country:DK"] }); + assert.deepEqual(rest, [second, weighted, must]); +}); From c99e91f5b9f352f383e2a332311e5fd064d04b03 Mon Sep 17 00:00:00 2001 From: Wolf Date: Wed, 30 Sep 2026 15:23:04 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Show=20the=20remote=20area=20on=20the=20Rol?= =?UTF-8?q?es=20badge=20and=20offer=20Remote=20=C2=B7=20=20suggesti?= =?UTF-8?q?ons=20on=20the=20Place=20rail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- app/static/roles.js | 9 +++++---- app/templates/roles.html | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/static/roles.js b/app/static/roles.js index 8c597a5..d1a0b50 100644 --- a/app/static/roles.js +++ b/app/static/roles.js @@ -85,7 +85,7 @@ "use strict"; const { api, esc, debounce, safeUrl, companies, loadCompanies, affinityControl, overridesControl, - judgeButtons, loadTracked, chipInput } = window; + judgeButtons, loadTracked, chipInput, remoteHelpers } = window; const $ = (sel, root = document) => root.querySelector(sel); // Below this the rail is over the feed rather than beside it, and the reader @@ -128,8 +128,9 @@ }; // The place suggestion's kind, as its hint says it: a `place:` token is a - // town (`places.suggest`). - const PLACE_KINDS = { country: "country", region: "region", place: "town" }; + // town, a `remote:` token the remote roles a person there can take, its + // count the roles it would find (`places.suggest`). + const PLACE_KINDS = { country: "country", region: "region", place: "town", remote: "remote" }; // Everything `clearFilters` has to put back, in one place, so a new filter // added here cannot be forgotten there. `company` and `place` are the @@ -889,7 +890,7 @@ /** Closed, pay, remote, function and seniority, as the row and the reader both show them. */ function badges(role) { - const words = [role.remote, role.function, role.seniority].filter(Boolean); + const words = [remoteHelpers.remoteBadge(role), role.function, role.seniority].filter(Boolean); const pay = payBadge(role); return (role.closed_at ? `closed` : "") + (pay ? `${esc(pay)}` : "") diff --git a/app/templates/roles.html b/app/templates/roles.html index 1e191d0..39ff2ae 100644 --- a/app/templates/roles.html +++ b/app/templates/roles.html @@ -166,6 +166,7 @@ applies all the same, and chips.css only adds to app.css. #} + {% endblock %} From 1c7bc7219880468055b3eff67cfe2ebf6e6ecdfd Mon Sep 17 00:00:00 2001 From: Wolf Date: Wed, 30 Sep 2026 15:23:04 +0200 Subject: [PATCH 3/4] Replace the agent's remote scope by Remote, open to someone in: chips written as one remote_from gate Co-Authored-By: Claude Opus 5.5 --- app/static/agents.js | 134 +++++++++++++++-------------- app/static/app.css | 1 + app/templates/settings/agents.html | 12 +-- 3 files changed, 78 insertions(+), 69 deletions(-) diff --git a/app/static/agents.js b/app/static/agents.js index ae35995..5643616 100644 --- a/app/static/agents.js +++ b/app/static/agents.js @@ -24,7 +24,7 @@ (function () { "use strict"; - const { api, count } = window; + const { api, count, remoteHelpers: rh } = window; const $ = (sel, root = document) => root.querySelector(sel); const DEFAULT_WEIGHTS = { fit: 0.6, recency: 0.2, affinity: 0.2, taste: 0.2 }; @@ -38,7 +38,7 @@ const EUROPE = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "IS", "LI", "NO", "GB", "CH", "EU"]; - const FIELDS = ["place", "country", "remote", "seniority", "function", "salary_min", + const FIELDS = ["place", "country", "remote", "remote_from", "seniority", "function", "salary_min", "currency", "permit", "languages", "company"]; const MODES = [["require", "must"], ["any", "one of"], ["prefer", "prefer"]]; const HYBRID_WEIGHT = 0.05; @@ -107,11 +107,33 @@ } // The countries Where offers, by name: Europe's, without EU, which is not - // a country but "open anywhere in Europe" and is said by Remote. + // a country but "open anywhere in Europe" and is picked in the remote line. const COUNTRIES = EUROPE.filter((c) => c !== "EU") .map((c) => [c, countryName(c)]) .sort((a, b) => a[1].localeCompare(b[1])); + /** @type {Map} the words of the `remote_from` values, by + * value, as `/api/places/labels` says them; a card and a chip fall back to + * `rh.fallbackLabel` until they are in */ + const placeNames = new Map(); + const placeLabel = (value) => placeNames.get(value) || rh.fallbackLabel(value, countryName); + + // The labels of the `remote_from` tokens in `gates` that are not known yet. + // A failure is toasted by `api()` and leaves the fallbacks. + async function nameRemote(gates) { + const missing = [...new Set(gates.filter((g) => g.field === "remote_from") + .flatMap((g) => g.values.map(String)))] + .filter((v) => v !== rh.ANYWHERE && !placeNames.has(v)); + if (!missing.length) return; + const p = new URLSearchParams(); + missing.forEach((t) => p.append("tokens", t)); + try { + for (const { token, label } of await api(`/api/places/labels?${p}`)) placeNames.set(token, label); + } catch (err) { + // the fallbacks stand + } + } + // "a, b or c": the values of one line. function orList(items) { return items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} or ${items[items.length - 1]}`; @@ -196,6 +218,7 @@ } if (gate.field === "place") return `in ${orList(towns(values))}`; if (gate.field === "remote") return orList(values); + if (gate.field === "remote_from") return rh.remoteSentence(values, placeLabel); if (gate.field === "company") return `at ${orList(values)}`; if (gate.field === "salary_min") return `paying at least ${values[0]}`; return `with ${gate.field.replace("_", " ")} ${values.join(", ")}`; @@ -203,14 +226,14 @@ // The Where block in words, one sentence of the lines a role may match, // with the one-of rows among them since they are the same group: "Keeps - // roles anywhere in Denmark, in Malmö, Lund or Helsingborg, or remote within - // Europe, and leaves out the rest." The lines add up, which the first + // roles anywhere in Denmark, in Malmö, Lund or Helsingborg, or remote from + // Denmark, Sweden or Germany, and leaves out the rest." The lines add up, which the first // wording ("Roles in ...") left the owner to guess. function whereSentence(where, others) { const parts = []; if (where.countries) parts.push(`anywhere ${phrase(where.countries)}`); if (where.places) parts.push(phrase(where.places)); - if (where.remote) parts.push(where.europe ? "remote within Europe" : "remote"); + if (where.remote && where.remote.values.length) parts.push(rh.remoteSentence(where.remote.values, placeLabel)); parts.push(...others.map(phrase)); if (!parts.length) return ""; const list = parts.length < 2 ? parts[0] : `${parts.slice(0, -1).join(", ")}, or ${parts[parts.length - 1]}`; @@ -218,11 +241,11 @@ } // The gates in words: where a role may be, then what it must meet, then - // what lifts it. "Keeps roles anywhere in Denmark, or remote within Europe, + // what lifts it. "Keeps roles anywhere in Denmark, or remote from anywhere, // and leaves out the rest. Only roles with seniority senior. Prefers // hybrid." function rulesLine(gates) { - const { where, rest } = distribute(gates); + const { where, rest } = rh.distribute(gates); const of = (mode) => rest.filter((g) => g.mode === mode); const must = of("require").map(phrase); const prefer = of("prefer").map((g) => phrase(g).replace(/^with /, "")); @@ -379,6 +402,38 @@ return { node: chips.node, values: () => [...chips.list] }; } + // "Remote, open to someone in": the values of a `remote_from` gate as chips, + // picked from the place suggestions that a remote hire can live in: + // countries, regions and Anywhere. `values()` are the gate's values + // (`country:DK`, `anywhere`), the chips say them in words. + function remoteInput(values, onChange) { + const root = el("div"); + root.id = "a-remote-from"; + const chips = window.chipInput(root, { + suggest: async (q) => { + const rows = await api(`/api/suggest/places?${new URLSearchParams({ q })}`); + const picks = []; + for (const s of rows) { + const value = rh.fromSuggestion(s); + if (value === null) continue; + picks.push(value === rh.ANYWHERE + ? { value, label: "Anywhere" } + : { value, label: s.label, hint: s.kind }); + } + const has = picks.some((p) => p.value === rh.ANYWHERE); + if (!has && rh.offersAnywhere(q)) picks.unshift({ value: rh.ANYWHERE, label: "Anywhere" }); + return picks; + }, + onChange: (items) => { + items.forEach((i) => placeNames.set(i.value, i.label)); + onChange(); + }, + placeholder: "Add a country, a region or Anywhere", label: "Remote, open to someone in", + }); + chips.set(values.map((v) => ({ value: v, label: placeLabel(v) }))); + return { node: root, values: () => chips.values().map((i) => i.value) }; + } + // Words as chips of free text, added on Enter or a comma, and one chip for // the spellings that fold alike. What is typed but not added yet counts, so // Save does not drop it. Towns and fetch terms both. @@ -490,46 +545,6 @@ return { node: row, read }; } - // Share out an agent's gates between the Where block and Other rules. Each - // Where line takes the first gate it can say whole; the rest are rows. A - // must or one-of gate with a weight other than the default stays a row, - // since Where would drop it. Remote within Europe is a must on country - // that is Europe and the countries line exactly, and only with Remote - // ticked; any other must on country is a row, and Remote reads anywhere. - function distribute(gates) { - const where = { countries: null, places: null, remote: null, europe: null, hybrid: null }; - const rest = []; - const musts = []; - const plain = (g) => g.weight === undefined || g.weight === 1; - const only = (g, value) => g.values.length === 1 && g.values[0] === value; - for (const g of gates) { - let slot = null; - if (g.field === "country" && g.mode === "require" && plain(g)) { - musts.push(g); - continue; - } - if (g.field === "country" && g.mode === "any" && plain(g)) slot = "countries"; - else if (g.field === "remote" && g.mode === "any" && plain(g) && only(g, "remote")) slot = "remote"; - else if (g.field === "place" && g.mode === "any" && plain(g)) slot = "places"; - else if (g.field === "remote" && g.mode === "prefer" && only(g, "hybrid")) slot = "hybrid"; - if (slot && !where[slot]) where[slot] = g; - else rest.push(g); - } - const within = new Set(europeWith(where.countries ? where.countries.values : [])); - for (const g of musts) { - const same = g.values.length === within.size && g.values.every((v) => within.has(v)); - if (where.remote && !where.europe && same) where.europe = g; - else rest.push(g); - } - return { where, rest }; - } - - // What Remote within Europe sends: Europe, and the countries line too, - // since the must holds for every role, not only the remote ones. - function europeWith(countries) { - return [...EUROPE, ...countries.filter((c) => !EUROPE.includes(c))]; - } - function form(row) { const div = el("article", "agent-card editing"); const f = $("#agent-form-template").content.querySelector("form").cloneNode(true); @@ -558,22 +573,15 @@ changed(f); }); - const { where, rest } = distribute(row ? row.gates : []); + const { where, rest } = rh.distribute(row ? row.gates : []); const countries = countryInput(where.countries ? where.countries.values : []); const places = wordInput(where.places ? where.places.values : [], "Add a town"); const terms = wordInput(row ? row.fetch_terms || [] : [], "machine learning, data science"); $("#a-terms", f).replaceWith(terms.node); $("#a-countries", f).replaceWith(countries.node); $("#a-towns", f).replaceWith(places.node); - const remote = $("#a-remote", f); - const scope = $("#a-remote-scope", f); - remote.checked = Boolean(where.remote); - // Anywhere when a must on country is a row, so ticking Remote does not - // stack a second one on it; else Europe, the usual answer. - const mustRow = rest.some((g) => g.field === "country" && g.mode === "require"); - scope.value = where.europe || !(where.remote || mustRow) ? "europe" : "anywhere"; - const offerScope = () => { scope.disabled = !remote.checked; }; - offerScope(); + const remoteFrom = remoteInput(where.remote ? where.remote.values : [], () => changed(f)); + $("#a-remote-from", f).replaceWith(remoteFrom.node); // The hybrid weight shows only when it is not the default; either way it // is sent back as it came. const hybridWeight = where.hybrid && where.hybrid.weight !== undefined ? where.hybrid.weight : HYBRID_WEIGHT; @@ -601,16 +609,14 @@ }); // The gates the Where block says, in the order the starter agents have - // them: the must on country, the lines, then hybrid. + // them: the lines, then hybrid. function whereGates() { const out = []; const within = countries.values(); const towns = places.values(); - if (remote.checked && scope.value === "europe") { - out.push({ field: "country", values: europeWith(within), mode: "require" }); - } + const from = remoteFrom.values(); if (within.length) out.push({ field: "country", values: within, mode: "any" }); - if (remote.checked) out.push({ field: "remote", values: ["remote"], mode: "any" }); + if (from.length) out.push({ field: "remote_from", values: from, mode: "any" }); if (towns.length) out.push({ field: "place", values: towns, mode: "any" }); if ($("#a-hybrid", f).checked) { out.push({ field: "remote", values: ["hybrid"], mode: "prefer", weight: Number($("#a-hybrid-weight", f).value) }); @@ -621,7 +627,6 @@ // under Where says them all, as the card will, rows included. const gates = () => whereGates().concat(rules.map((r) => r.read())); const view = () => { - offerScope(); $("#a-gates", f).value = JSON.stringify(gates(), null, 2); $("#a-where-sum", f).textContent = rulesLine(gates()) || "Keeps roles anywhere."; }; @@ -795,6 +800,7 @@ async function load() { agents = await api("/api/agents"); + await nameRemote(agents.flatMap((a) => a.gates || [])); // A card is only worded by it, so a failure leaves the cards as they were. try { stageOn = Object.fromEntries((await api("/api/stages")).map((s) => [s.name, s.on])); diff --git a/app/static/app.css b/app/static/app.css index 5cb13cf..3d36204 100644 --- a/app/static/app.css +++ b/app/static/app.css @@ -1249,6 +1249,7 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di .where-line { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .9rem; } .where-line > span, .where-line > label { flex: none; min-width: 9rem; } .where-line .chips { flex: 1 1 12rem; } +.where-line .chip-input { flex: 1 1 12rem; min-width: 0; margin: 0; } /* Hybrid ranks rather than filters, so it stands apart from the lines, and the sentence under it says the whole block. */ .agent-form .where-rank { margin-top: .4rem; } diff --git a/app/templates/settings/agents.html b/app/templates/settings/agents.html index 4609ba0..31d0783 100644 --- a/app/templates/settings/agents.html +++ b/app/templates/settings/agents.html @@ -39,12 +39,10 @@ Towns are for places outside the countries above: with Denmark above, Malmö here adds Malmö to all of Denmark. A town inside a country above changes nothing, since the whole country is in already.
- - + Remote, open to someone in: +
+ A remote role is kept when it can be worked from one of these; Anywhere is for roles open worldwide. A remote role whose area is not stated yet ranks until extract reads the posting. This one ranks rather than filters: a hybrid role gains a little.

@@ -96,5 +94,9 @@ {% endblock %} {% block scripts %} +{# chips.css only adds to app.css; base.html has no head block for it. #} + + + {% endblock %} From 888586c29b9489e306728ff0efae4f5745399044 Mon Sep 17 00:00:00 2001 From: Wolf Date: Wed, 30 Sep 2026 15:31:40 +0200 Subject: [PATCH 4/4] Make the agent's scope a line of its own: Only roles in Europe, chosen countries or Everywhere, read and written as the require gate on country Co-Authored-By: Claude Opus 5.5 --- app/static/agents.js | 77 ++++++++++++++++---------- app/static/remote.js | 76 ++++++++++++++++---------- app/static/roles.js | 14 +++-- app/templates/settings/agents.html | 19 ++++++- tests/js/remote.test.mjs | 88 +++++++++++++++++++----------- 5 files changed, 179 insertions(+), 95 deletions(-) diff --git a/app/static/agents.js b/app/static/agents.js index 5643616..2fa9ec5 100644 --- a/app/static/agents.js +++ b/app/static/agents.js @@ -33,11 +33,8 @@ // best `summarise_top` at `summarise_min` or more a summary. const DEFAULT_LIMITS = { extract_top: 500, extract_min: 0.55, summarise_top: 30, summarise_min: 0.65 }; const NEW = "new"; - // Europe as the starter agents in config.example.yaml spell it: the EEA, - // the UK and Switzerland, and EU for a role open anywhere in Europe. - const EUROPE = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", - "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", - "IS", "LI", "NO", "GB", "CH", "EU"]; + // Europe as the starter agents spell it (static/remote.js). + const EUROPE = rh.EUROPE; const FIELDS = ["place", "country", "remote", "remote_from", "seniority", "function", "salary_min", "currency", "permit", "languages", "company"]; const MODES = [["require", "must"], ["any", "one of"], ["prefer", "prefer"]]; @@ -224,24 +221,35 @@ return `with ${gate.field.replace("_", " ")} ${values.join(", ")}`; } - // The Where block in words, one sentence of the lines a role may match, - // with the one-of rows among them since they are the same group: "Keeps - // roles anywhere in Denmark, in Malmö, Lund or Helsingborg, or remote from - // Denmark, Sweden or Germany, and leaves out the rest." The lines add up, which the first - // wording ("Roles in ...") left the owner to guess. + // The scope of the Where block in words: "Within Europe", "Within Denmark or + // Sweden", "Everywhere". + function scopeWords(scope) { + if (scope.kind === "everywhere") return "Everywhere"; + if (scope.kind === "europe") return "Within Europe"; + return `Within ${phrase({ field: "country", values: scope.values }).replace(/^in /, "")}`; + } + + // The Where block in words, one sentence led by its scope, then the lines a + // role may match, with the one-of rows among them since they are the same + // group: "Within Europe: keeps roles anywhere in Denmark, in Malmö, Lund or + // Helsingborg, or remote, and leaves out the rest." The lines add up, which + // the first wording ("Roles in ...") left the owner to guess. function whereSentence(where, others) { const parts = []; if (where.countries) parts.push(`anywhere ${phrase(where.countries)}`); if (where.places) parts.push(phrase(where.places)); - if (where.remote && where.remote.values.length) parts.push(rh.remoteSentence(where.remote.values, placeLabel)); + if (where.remote.mode === "scope") parts.push("remote"); + if (where.remote.mode === "from" && where.remote.values.length) { + parts.push(rh.remoteSentence(where.remote.values, placeLabel)); + } parts.push(...others.map(phrase)); - if (!parts.length) return ""; + if (!parts.length) return where.scope.kind === "everywhere" ? "" : `${scopeWords(where.scope)}: keeps every role.`; const list = parts.length < 2 ? parts[0] : `${parts.slice(0, -1).join(", ")}, or ${parts[parts.length - 1]}`; - return `Keeps roles ${list}, and leaves out the rest.`; + return `${scopeWords(where.scope)}: keeps roles ${list}, and leaves out the rest.`; } // The gates in words: where a role may be, then what it must meet, then - // what lifts it. "Keeps roles anywhere in Denmark, or remote from anywhere, + // what lifts it. "Within Europe: keeps roles anywhere in Denmark, or remote, // and leaves out the rest. Only roles with seniority senior. Prefers // hybrid." function rulesLine(gates) { @@ -402,10 +410,10 @@ return { node: chips.node, values: () => [...chips.list] }; } - // "Remote, open to someone in": the values of a `remote_from` gate as chips, - // picked from the place suggestions that a remote hire can live in: - // countries, regions and Anywhere. `values()` are the gate's values - // (`country:DK`, `anywhere`), the chips say them in words. + // "Only when open to someone in": the values of a `remote_from` gate as + // chips, picked from the place suggestions that a remote hire can live in: + // countries and regions. `values()` are the gate's values (`country:DK`), + // the chips say them in words. function remoteInput(values, onChange) { const root = el("div"); root.id = "a-remote-from"; @@ -415,20 +423,15 @@ const picks = []; for (const s of rows) { const value = rh.fromSuggestion(s); - if (value === null) continue; - picks.push(value === rh.ANYWHERE - ? { value, label: "Anywhere" } - : { value, label: s.label, hint: s.kind }); + if (value !== null) picks.push({ value, label: s.label, hint: s.kind }); } - const has = picks.some((p) => p.value === rh.ANYWHERE); - if (!has && rh.offersAnywhere(q)) picks.unshift({ value: rh.ANYWHERE, label: "Anywhere" }); return picks; }, onChange: (items) => { items.forEach((i) => placeNames.set(i.value, i.label)); onChange(); }, - placeholder: "Add a country, a region or Anywhere", label: "Remote, open to someone in", + placeholder: "Add a country or a region", label: "Remote, open to someone in", }); chips.set(values.map((v) => ({ value: v, label: placeLabel(v) }))); return { node: root, values: () => chips.values().map((i) => i.value) }; @@ -574,14 +577,26 @@ }); const { where, rest } = rh.distribute(row ? row.gates : []); + const scope = $("#a-scope", f); + scope.value = where.scope.kind; + const scoped = countryInput(where.scope.values); const countries = countryInput(where.countries ? where.countries.values : []); const places = wordInput(where.places ? where.places.values : [], "Add a town"); const terms = wordInput(row ? row.fetch_terms || [] : [], "machine learning, data science"); $("#a-terms", f).replaceWith(terms.node); + $("#a-scope-countries", f).replaceWith(scoped.node); $("#a-countries", f).replaceWith(countries.node); $("#a-towns", f).replaceWith(places.node); - const remoteFrom = remoteInput(where.remote ? where.remote.values : [], () => changed(f)); + const remoteMode = $("#a-remote", f); + remoteMode.value = where.remote.mode; + const remoteFrom = remoteInput(where.remote.mode === "from" ? where.remote.values : [], () => changed(f)); $("#a-remote-from", f).replaceWith(remoteFrom.node); + // Only the pick that is on shows its chips. + const offer = () => { + scoped.node.hidden = scope.value !== "countries"; + remoteFrom.node.hidden = remoteMode.value !== "from"; + }; + offer(); // The hybrid weight shows only when it is not the default; either way it // is sent back as it came. const hybridWeight = where.hybrid && where.hybrid.weight !== undefined ? where.hybrid.weight : HYBRID_WEIGHT; @@ -609,14 +624,19 @@ }); // The gates the Where block says, in the order the starter agents have - // them: the lines, then hybrid. + // them: the scope, the lines, then hybrid. function whereGates() { const out = []; const within = countries.values(); const towns = places.values(); const from = remoteFrom.values(); + if (scope.value === "europe") out.push({ field: "country", values: rh.europeWith(within), mode: "require" }); + if (scope.value === "countries" && scoped.values().length) { + out.push({ field: "country", values: scoped.values(), mode: "require" }); + } if (within.length) out.push({ field: "country", values: within, mode: "any" }); - if (from.length) out.push({ field: "remote_from", values: from, mode: "any" }); + if (remoteMode.value === "scope") out.push({ field: "remote", values: ["remote"], mode: "any" }); + if (remoteMode.value === "from" && from.length) out.push({ field: "remote_from", values: from, mode: "any" }); if (towns.length) out.push({ field: "place", values: towns, mode: "any" }); if ($("#a-hybrid", f).checked) { out.push({ field: "remote", values: ["hybrid"], mode: "prefer", weight: Number($("#a-hybrid-weight", f).value) }); @@ -627,6 +647,7 @@ // under Where says them all, as the card will, rows included. const gates = () => whereGates().concat(rules.map((r) => r.read())); const view = () => { + offer(); $("#a-gates", f).value = JSON.stringify(gates(), null, 2); $("#a-where-sum", f).textContent = rulesLine(gates()) || "Keeps roles anywhere."; }; diff --git a/app/static/remote.js b/app/static/remote.js index 8b15c87..70ddaa1 100644 --- a/app/static/remote.js +++ b/app/static/remote.js @@ -24,21 +24,12 @@ } /** A `/api/suggest/places` answer as the value of a `remote_from` gate, or - null when the Where block does not offer it: countries, regions and - Anywhere. A town, or a remote token that is not Anywhere (the block's - own country pick is the plain one), is left out. */ + null when the Where block does not offer it: countries and regions. A + town or a remote token is left out; the block's own country pick is the + plain one. */ function fromSuggestion(s) { const token = String(s.token || ""); - if (token === `remote:${ANYWHERE}`) return ANYWHERE; - if (token.startsWith("country:") || token.startsWith("region:")) return token; - return null; - } - - /** The words a person can type for Anywhere, which the suggestions may or - may not carry. */ - function offersAnywhere(q) { - const text = String(q).trim().toLowerCase(); - return text.length > 0 && ["anywhere", "worldwide"].some((w) => w.startsWith(text)); + return token.startsWith("country:") || token.startsWith("region:") ? token : null; } /** The chip label of a gate value when the server has not said it yet. */ @@ -57,36 +48,63 @@ return `remote from ${list}`; } + /** Europe as the starter agents in config.example.yaml spell it: the EEA, + the UK and Switzerland, and EU for a role open anywhere in Europe. */ + const EUROPE = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", + "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", + "IS", "LI", "NO", "GB", "CH", "EU"]; + + /** What "Only roles in: Europe" sends: Europe, and the countries line too, + since the require gate holds for every role, not only the remote ones. */ + function europeWith(countries) { + return [...EUROPE, ...countries.filter((c) => !EUROPE.includes(c))]; + } + /** Share out an agent's gates between the Where block and Other rules. Each Where line takes the first gate it can say whole; the rest are rows. A must or one-of gate with a weight other than the default stays a row, - since Where would drop it. The remote line is a `remote_from` one-of, or - the older one-of on `remote: [remote]`, which reads as remote from - Anywhere; both save as `remote_from`. Every require gate on country is a - row, "within Europe" among them: it holds for every role and not only - the remote ones, so the block does not fold it into the remote line. */ + since Where would drop it. + + The scope line is the first plain require gate on country: `europe` + when it is exactly Europe and the countries line (`europeWith`), + `countries` with its codes as chips otherwise, `everywhere` when there + is none. Any other require gate on country is a row. The remote line is + `scope` for the one-of on `remote: [remote]` (remote, within the + scope), `from` for a one-of on `remote_from`, else `none`; when both + are there `remote_from` wins and the plain one stays a row. */ function distribute(gates) { - const where = { countries: null, places: null, remote: null, hybrid: null }; + const where = { scope: null, countries: null, places: null, remote: { mode: "none", values: [] }, hybrid: null }; const rest = []; const plain = (g) => g.weight === undefined || g.weight === 1; const only = (g, value) => g.values.length === 1 && g.values[0] === value; + let must = null; let older = null; + let from = null; for (const g of gates) { - if (g.field === "country" && g.mode === "any" && plain(g) && !where.countries) where.countries = g; + if (g.field === "country" && g.mode === "require" && plain(g) && !must) must = g; + else if (g.field === "country" && g.mode === "any" && plain(g) && !where.countries) where.countries = g; else if (g.field === "place" && g.mode === "any" && plain(g) && !where.places) where.places = g; - else if (g.field === "remote_from" && g.mode === "any" && plain(g) && !where.remote) { - where.remote = { values: g.values.map(String) }; - } else if (g.field === "remote" && g.mode === "any" && plain(g) && only(g, "remote") && !older) { - older = g; - } else if (g.field === "remote" && g.mode === "prefer" && only(g, "hybrid") && !where.hybrid) where.hybrid = g; + else if (g.field === "remote_from" && g.mode === "any" && plain(g) && !from) from = g; + else if (g.field === "remote" && g.mode === "any" && plain(g) && only(g, "remote") && !older) older = g; + else if (g.field === "remote" && g.mode === "prefer" && only(g, "hybrid") && !where.hybrid) where.hybrid = g; else rest.push(g); } - if (older) { - if (where.remote) rest.push(older); - else where.remote = { values: [ANYWHERE] }; + if (from) { + where.remote = { mode: "from", values: from.values.map(String) }; + if (older) rest.push(older); + } else if (older) { + where.remote = { mode: "scope", values: [] }; + } + if (!must) { + where.scope = { kind: "everywhere", values: [] }; + } else { + const values = must.values.map(String); + const within = new Set(europeWith(where.countries ? where.countries.values.map(String) : [])); + const europe = values.length === within.size && values.every((v) => within.has(v)); + where.scope = europe ? { kind: "europe", values: [] } : { kind: "countries", values }; } return { where, rest }; } - window.remoteHelpers = { ANYWHERE, remoteBadge, fromSuggestion, offersAnywhere, fallbackLabel, remoteSentence, distribute }; + window.remoteHelpers = { ANYWHERE, EUROPE, europeWith, remoteBadge, fromSuggestion, fallbackLabel, remoteSentence, distribute }; })(); diff --git a/app/static/roles.js b/app/static/roles.js index d1a0b50..a81d511 100644 --- a/app/static/roles.js +++ b/app/static/roles.js @@ -128,7 +128,8 @@ }; // The place suggestion's kind, as its hint says it: a `place:` token is a - // town, a `remote:` token the remote roles a person there can take, its + // town, a `remote:` token remote roles (`remote:any` within the viewing + // agent's scope, `remote:country:DK` those a person there can take), its // count the roles it would find (`places.suggest`). const PLACE_KINDS = { country: "country", region: "region", place: "town", remote: "remote" }; @@ -1659,11 +1660,16 @@ placeholder: "Company", label: "Company", }); placeChips = chipInput($("#f-place"), { - suggest: (q) => api(`/api/suggest/places?${new URLSearchParams({ q })}`) - .then((rows) => rows.map((s) => ({ + suggest: (q) => { + // The viewing agent, so "Remote" counts the remote roles within its + // scope; the server may ignore it. + const p = new URLSearchParams({ q }); + if (state.filter.agent !== null) p.set("agent", String(state.filter.agent)); + return api(`/api/suggest/places?${p}`).then((rows) => rows.map((s) => ({ value: s.token, label: s.label, hint: `${PLACE_KINDS[s.kind] || s.kind} · ${number.format(s.count)}`, - }))), + }))); + }, onChange: (items) => { items.forEach((i) => placeLabels.set(i.value, i.label)); setFilter({ places: items.map((i) => i.value) }); diff --git a/app/templates/settings/agents.html b/app/templates/settings/agents.html index 31d0783..3fe8691 100644 --- a/app/templates/settings/agents.html +++ b/app/templates/settings/agents.html @@ -29,6 +29,16 @@
Where can the role be? Each line adds places. A role is kept when it fits at least one line, so a line more means more roles, never fewer. With every line empty a role can be anywhere. A role whose location is not known yet ranks until extract reads the posting. +
+ Only roles in: + +
+
+ Every role must be in this, whatever the lines below add. A company set to All countries is read within this.
Anywhere in
@@ -39,10 +49,15 @@
Towns are for places outside the countries above: with Denmark above, Malmö here adds Malmö to all of Denmark. A town inside a country above changes nothing, since the whole country is in already.
- Remote, open to someone in: + Remote: +
- A remote role is kept when it can be worked from one of these; Anywhere is for roles open worldwide. A remote role whose area is not stated yet ranks until extract reads the posting. + Remote roles are kept on top of the lines above. A remote role whose area is not stated yet ranks until extract reads the posting. This one ranks rather than filters: a hybrid role gains a little.

diff --git a/tests/js/remote.test.mjs b/tests/js/remote.test.mjs index 1cde1e9..aa233fe 100644 --- a/tests/js/remote.test.mjs +++ b/tests/js/remote.test.mjs @@ -31,22 +31,15 @@ test("the badge leaves the other words as they are, and a role with none blank", assert.equal(rh.remoteBadge(null), ""); }); -test("a suggestion is offered to the remote line as a country, a region or Anywhere", () => { +test("a suggestion is offered to the remote line as a country or a region only", () => { assert.equal(rh.fromSuggestion({ token: "country:DK", kind: "country" }), "country:DK"); assert.equal(rh.fromSuggestion({ token: "country:EU", kind: "country" }), "country:EU"); assert.equal(rh.fromSuggestion({ token: "region:oresund", kind: "region" }), "region:oresund"); - assert.equal(rh.fromSuggestion({ token: "remote:anywhere", kind: "remote" }), "anywhere"); + assert.equal(rh.fromSuggestion({ token: "remote:any", kind: "remote" }), null); assert.equal(rh.fromSuggestion({ token: "remote:country:DK", kind: "remote" }), null); assert.equal(rh.fromSuggestion({ token: "place:1", kind: "place" }), null); }); -test("Anywhere is offered for the words that start it", () => { - assert.equal(rh.offersAnywhere("any"), true); - assert.equal(rh.offersAnywhere(" World"), true); - assert.equal(rh.offersAnywhere("den"), false); - assert.equal(rh.offersAnywhere(""), false); -}); - test("a value has a label before the server has said it", () => { assert.equal(label("anywhere"), "Anywhere"); assert.equal(label("country:DK"), "Denmark"); @@ -65,46 +58,77 @@ test("the sentence lists the areas, and says anywhere in lower case", () => { const older = { field: "remote", values: ["remote"], mode: "any" }; const from = (...values) => ({ field: "remote_from", values, mode: "any" }); const hybrid = { field: "remote", values: ["hybrid"], mode: "prefer", weight: 0.05 }; -const europe = { field: "country", values: ["DK", "SE", "EU"], mode: "require" }; +const dk = { field: "country", values: ["DK"], mode: "any" }; +const must = (...values) => ({ field: "country", values, mode: "require" }); +const europe = must(...rh.EUROPE); -test("no remote gate: the remote line is empty", () => { - const { where, rest } = rh.distribute([{ field: "country", values: ["DK"], mode: "any" }, hybrid]); - assert.equal(where.remote, null); - assert.equal(where.hybrid, hybrid); +test("no gates: everywhere, no remote", () => { + const { where, rest } = rh.distribute([]); + assert.deepEqual(where.scope, { kind: "everywhere", values: [] }); + assert.deepEqual(where.remote, { mode: "none", values: [] }); assert.deepEqual(rest, []); }); -test("a remote_from gate loads into the remote line", () => { - const { where, rest } = rh.distribute([from("country:DK", "anywhere")]); - assert.deepEqual(where.remote, { values: ["country:DK", "anywhere"] }); +test("the Europe list is the Europe scope", () => { + const { where, rest } = rh.distribute([europe, dk, older]); + assert.equal(where.scope.kind, "europe"); + assert.equal(where.countries.values[0], "DK"); assert.deepEqual(rest, []); }); -test("the older remote gate loads as remote from Anywhere", () => { - const { where, rest } = rh.distribute([older]); - assert.deepEqual(where.remote, { values: ["anywhere"] }); +test("Europe with the countries line added is still the Europe scope", () => { + const us = { field: "country", values: ["US"], mode: "any" }; + const { where } = rh.distribute([must(...rh.europeWith(["US"])), us]); + assert.equal(where.scope.kind, "europe"); + // The same gate without the line's country is not exactly Europe: chips. + assert.equal(rh.distribute([europe, us]).where.scope.kind, "countries"); +}); + +test("any other require gate on country is the scope with its codes as chips", () => { + const { where, rest } = rh.distribute([must("DK", "SE"), dk]); + assert.deepEqual(where.scope, { kind: "countries", values: ["DK", "SE"] }); assert.deepEqual(rest, []); }); -test("a remote_from gate wins over the older one, which stays a row", () => { +test("a second or weighted require gate on country stays a row", () => { + const second = must("NO"); + const weighted = { ...must("DE"), weight: 2 }; + const { where, rest } = rh.distribute([europe, second, weighted]); + assert.equal(where.scope.kind, "europe"); + assert.deepEqual(rest, [second, weighted]); +}); + +test("a require gate on another field is a row and leaves the scope everywhere", () => { + const level = { field: "seniority", values: ["senior"], mode: "require" }; + const { where, rest } = rh.distribute([level]); + assert.equal(where.scope.kind, "everywhere"); + assert.deepEqual(rest, [level]); +}); + +test("remote, three modes: the plain gate is within the scope", () => { + const scope = rh.distribute([older, hybrid]); + assert.deepEqual(scope.where.remote, { mode: "scope", values: [] }); + assert.equal(scope.where.hybrid, hybrid); + assert.deepEqual(scope.rest, []); + assert.deepEqual(rh.distribute([hybrid]).where.remote, { mode: "none", values: [] }); + const named = rh.distribute([from("country:DK", "region:oresund")]); + assert.deepEqual(named.where.remote, { mode: "from", values: ["country:DK", "region:oresund"] }); + assert.deepEqual(named.rest, []); +}); + +test("a remote_from gate wins over the plain one, which stays a row", () => { for (const gates of [[older, from("country:DK")], [from("country:DK"), older]]) { const { where, rest } = rh.distribute(gates); - assert.deepEqual(where.remote, { values: ["country:DK"] }); + assert.deepEqual(where.remote, { mode: "from", values: ["country:DK"] }); assert.deepEqual(rest, [older]); } }); -test("the within Europe must is a row, kept whole", () => { - const { where, rest } = rh.distribute([europe, older]); - assert.deepEqual(where.remote, { values: ["anywhere"] }); - assert.deepEqual(rest, [europe]); -}); - test("a second remote_from gate, a weighted one or a must stays a row", () => { const second = from("country:SE"); const weighted = { ...from("country:DE"), weight: 2 }; - const must = { field: "remote_from", values: ["country:DK"], mode: "require" }; - const { where, rest } = rh.distribute([from("country:DK"), second, weighted, must]); - assert.deepEqual(where.remote, { values: ["country:DK"] }); - assert.deepEqual(rest, [second, weighted, must]); + const required = { field: "remote_from", values: ["country:DK"], mode: "require" }; + const { where, rest } = rh.distribute([from("country:DK"), second, weighted, required]); + assert.deepEqual(where.remote, { mode: "from", values: ["country:DK"] }); + assert.deepEqual(rest, [second, weighted, required]); });