Merge branch 'where-simple'

This commit is contained in:
Wolf committed 2026-09-29 16:46:35 +02:00
commit 9e92be848a
3 files changed
+213 -114

No files matched your search

+178 -92
View File
@@ -5,9 +5,10 @@
* switch, its prompts, its gates in words, its weights, and a link to the
* Roles tab in its order. The prompts are the body, since fit is measured
* against the one a role fits best; the weights only share out the terms.
* The form edits the prompts as rows, and the gates as a Where block for the
* usual location rules over a row per remaining rule; a gate Where cannot
* say lands in a row, so a load and a save lose nothing. Edit turns a card
* The form edits the prompts as rows, and the gates as a Where block, a
* short list of lines a role passes by matching any one of, over a row per
* remaining rule under Advanced; a gate Where cannot say lands in a row, so
* a load and a save lose nothing. Edit turns a card
* into the form from the page's `<template>`, in place, and New agent puts a
* blank card on top in the same state. One card edits at a time, so the
* form's ids stay unique. Votes, liked companies and scores are the agent's,
@@ -101,6 +102,29 @@
}
}
// 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.
const COUNTRIES = EUROPE.filter((c) => c !== "EU")
.map((c) => [c, countryName(c)])
.sort((a, b) => a[1].localeCompare(b[1]));
// "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]}`;
}
// A town without its accents, lower case: "Malmo" is "Malmö" spelt for a
// board that writes ASCII, one town with two spellings.
function fold(text) {
return String(text).normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
}
// The towns, one spelling each: the first of those that fold alike.
function towns(values) {
const seen = new Set();
return values.map(String).filter((v) => !seen.has(fold(v)) && seen.add(fold(v)));
}
// Until the backend returns `prompts`: an intent is one prompt named after its agent.
function promptsOf(row) {
if (row.prompts) return row.prompts;
@@ -157,38 +181,48 @@
return `fit ${w.fit} · newness ${w.recency} · companies ${w.affinity} · liked ${w.taste}`;
}
// One gate as a phrase: "in Denmark", "remote", "seniority senior, staff".
// Europe, whole, is one word rather than 33 countries.
// One gate as a phrase: "in Denmark or Sweden", "remote", "with seniority
// senior, staff". Europe, whole, is one word rather than 33 countries.
function phrase(gate) {
const values = gate.values.map(String);
if (gate.field === "country") {
const europe = EUROPE.every((c) => values.includes(c));
const rest = values.filter((v) => !(europe && EUROPE.includes(v))).map(countryName);
return `in ${(europe ? ["Europe", ...rest] : rest).join(", ")}`;
return `in ${orList(europe ? ["Europe", ...rest] : rest)}`;
}
if (gate.field === "place") return `in ${values.join(", ")}`;
if (gate.field === "remote") return values.join(" or ");
if (gate.field === "company") return `at ${values.join(", ")}`;
if (gate.field === "place") return `in ${orList(towns(values))}`;
if (gate.field === "remote") return orList(values);
if (gate.field === "company") return `at ${orList(values)}`;
if (gate.field === "salary_min") return `paying at least ${values[0]}`;
return `${gate.field} ${values.join(", ")}`;
return `with ${gate.field.replace("_", " ")} ${values.join(", ")}`;
}
// The gates in words: what a role must meet, then the one group it must
// meet one of, then what lifts it. "In Europe, and in Denmark or remote or
// in Malmö, Lund. Prefers hybrid."
// 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: "Roles in
// Denmark, in Malmö, Lund or Helsingborg, or remote within Europe."
function whereSentence(where, others) {
const parts = [];
if (where.countries) parts.push(phrase(where.countries));
if (where.places) parts.push(phrase(where.places));
if (where.remote) parts.push(where.europe ? "remote within Europe" : "remote");
parts.push(...others.map(phrase));
if (!parts.length) return "";
return `Roles ${parts.length < 2 ? parts[0] : `${parts.slice(0, -1).join(", ")}, or ${parts[parts.length - 1]}`}.`;
}
// The gates in words: where a role may be, then what it must meet, then
// what lifts it. "Roles in Denmark, or remote within Europe. Only roles
// with seniority senior. Prefers hybrid."
function rulesLine(gates) {
const of = (mode) => gates.filter((g) => g.mode === mode).map(phrase);
const must = of("require");
const any = of("any");
const prefer = of("prefer");
const { where, rest } = 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 /, ""));
if (where.hybrid) prefer.unshift("hybrid");
const sentences = [];
const first = [];
if (must.length) first.push(must.join(", "));
if (any.length) first.push(`${must.length ? "and " : ""}${any.join(" or ")}`);
if (first.length) {
const text = first.join(", ");
sentences.push(`${text[0].toUpperCase()}${text.slice(1)}.`);
}
const any = whereSentence(where, of("any"));
if (any) sentences.push(any);
if (must.length) sentences.push(`Only roles ${must.join(" and ")}.`);
if (prefer.length) sentences.push(`Prefers ${prefer.join("; ")}.`);
return sentences.join(" ");
}
@@ -272,48 +306,36 @@
}
// A list of values as chips, the rail's tags with news's filter pills' ×,
// and a box after them that adds on Enter or a comma. Country codes are
// `upper`, and all of Europe is one chip. What is typed but not added yet
// counts, so Save does not drop it.
function chipInput(values, label, placeholder, upper) {
// then `entry`, the control that adds to it. `label` is a value in words.
// `group` puts values that are one thing on one chip, whose × drops them
// all. `drawn` runs after each redraw, for an entry that lists what is left.
function chipList(values, entry, { label = String, group = (v) => v, drawn = () => {} } = {}) {
const list = values.map(String);
const box = el("div", "chips");
const input = el("input");
input.type = "text";
input.spellcheck = false;
input.placeholder = placeholder;
input.setAttribute("aria-label", label);
const split = (text) => text.split(",").map((v) => (upper ? v.trim().toUpperCase() : v.trim())).filter(Boolean);
const europe = () => upper && EUROPE.every((c) => list.includes(c));
function chip(text, title, drop) {
function chip(value) {
const same = list.filter((v) => group(v) === group(value));
const text = label(value);
const button = el("button", "tag", `${text} `);
button.type = "button";
button.title = title;
button.title = same.length > 1 ? `Also matches ${same.slice(1).join(", ")}` : value;
button.setAttribute("aria-label", `Remove ${text}`);
const x = el("span", "", "×");
x.setAttribute("aria-hidden", "true");
button.appendChild(x);
button.addEventListener("click", () => {
drop();
list.splice(0, list.length, ...list.filter((v) => group(v) !== group(value)));
draw();
changed(box);
input.focus();
entry.focus();
});
return button;
}
function draw() {
const whole = europe();
const chips = whole
? [chip("Europe", EUROPE.join(" "), () => list.splice(0, list.length, ...list.filter((v) => !EUROPE.includes(v))))]
: [];
for (const value of list) {
if (whole && EUROPE.includes(value)) continue;
chips.push(chip(value, upper ? countryName(value) : "", () => list.splice(list.indexOf(value), 1)));
}
box.replaceChildren(...chips, input);
const firsts = list.filter((v, i) => list.findIndex((w) => group(w) === group(v)) === i);
box.replaceChildren(...firsts.map(chip), entry);
drawn(list);
}
function add(more) {
@@ -323,24 +345,56 @@
if (list.length !== before) changed(box);
}
draw();
return { node: box, list, add };
}
// Countries as chips by name, added from a select of Europe's by name;
// the select leaves out the ones already chips.
function countryInput(values) {
const pick = el("select");
pick.setAttribute("aria-label", "Add a country");
const offer = (list) => {
const blank = el("option", "", "Add a country");
blank.value = "";
const left = COUNTRIES.filter(([code]) => !list.includes(code)).map(([code, name]) => {
const option = el("option", "", name);
option.value = code;
return option;
});
pick.replaceChildren(blank, ...left);
pick.value = "";
};
const chips = chipList(values, pick, { label: countryName, drawn: offer });
pick.addEventListener("change", () => { if (pick.value) chips.add([pick.value]); });
return { node: chips.node, values: () => [...chips.list] };
}
// Towns as chips of free text, added on Enter or a comma, and one chip for
// the spellings of a town. What is typed but not added yet counts, so Save
// does not drop it.
function townInput(values) {
const input = el("input");
input.type = "text";
input.spellcheck = false;
input.placeholder = "Add a town";
input.setAttribute("aria-label", "Add a town");
const split = (text) => text.split(",").map((v) => v.trim()).filter(Boolean);
const chips = chipList(values, input, { group: fold });
const take = () => {
const typed = split(input.value);
input.value = "";
chips.add(typed);
};
input.addEventListener("keydown", (event) => {
if (event.key !== "Enter" && event.key !== ",") return;
event.preventDefault();
const typed = split(input.value);
input.value = "";
add(typed);
take();
});
input.addEventListener("blur", () => {
const typed = split(input.value);
input.value = "";
add(typed);
});
draw();
input.addEventListener("blur", take);
return {
node: box,
add,
whole: europe,
values: () => [...list, ...split(input.value).filter((v) => !list.includes(v))],
node: chips.node,
values: () => [...chips.list, ...split(input.value).filter((v) => !chips.list.includes(v))],
};
}
@@ -422,25 +476,43 @@
// 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.
// 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 = { in: null, anyCountry: null, remote: null, places: null, hybrid: null };
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)) slot = "in";
else if (g.field === "country" && g.mode === "any" && plain(g)) slot = "anyCountry";
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);
@@ -470,20 +542,26 @@
});
const { where, rest } = distribute(row ? row.gates : []);
const within = chipInput(where.in ? where.in.values : [], "Only roles in these countries", "DK, SE", true);
const anyCountry = chipInput(where.anyCountry ? where.anyCountry.values : [], "Or in one of these countries", "DK", true);
const places = chipInput(where.places ? where.places.values : [], "Or in one of these places", "Malmö, Lund", false);
$("#a-in", f).replaceWith(within.node);
$("#a-any-country", f).replaceWith(anyCountry.node);
$("#a-places", f).replaceWith(places.node);
// Europe is offered while it is not whole in the list already.
const europe = $("#a-europe", f);
const offerEurope = () => { europe.hidden = within.whole(); };
europe.addEventListener("click", () => within.add(EUROPE));
offerEurope();
$("#a-remote", f).checked = Boolean(where.remote);
const countries = countryInput(where.countries ? where.countries.values : []);
const places = townInput(where.places ? where.places.values : []);
$("#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();
// 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;
$("#a-hybrid", f).checked = Boolean(where.hybrid);
$("#a-hybrid-weight", f).value = where.hybrid && where.hybrid.weight !== undefined ? where.hybrid.weight : HYBRID_WEIGHT;
$("#a-hybrid-weight", f).value = hybridWeight;
$("#a-hybrid-weight-line", f).hidden = hybridWeight === HYBRID_WEIGHT;
$("details.advanced", f).open = rest.length > 0;
const rules = [];
const dropRule = (node) => {
@@ -503,23 +581,31 @@
changed(f);
});
// The gates Save sends: the Where lines that say something, then the rows.
function gates() {
// The gates the Where block says, in the order the starter agents have
// them: the must on country, the lines, then hybrid.
function whereGates() {
const out = [];
const line = (chips, field, mode) => {
const values = chips.values();
if (values.length) out.push({ field, values, mode });
};
line(within, "country", "require");
line(anyCountry, "country", "any");
if ($("#a-remote", f).checked) out.push({ field: "remote", values: ["remote"], mode: "any" });
line(places, "place", "any");
const within = countries.values();
const towns = places.values();
if (remote.checked && scope.value === "europe") {
out.push({ field: "country", values: europeWith(within), mode: "require" });
}
if (within.length) out.push({ field: "country", values: within, mode: "any" });
if (remote.checked) out.push({ field: "remote", values: ["remote"], 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) });
}
return out.concat(rules.map((r) => r.read()));
return out;
}
const view = () => { $("#a-gates", f).value = JSON.stringify(gates(), null, 2); };
// The gates Save sends: the Where block's, then the rows. The sentence
// 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()) || "Roles anywhere.";
};
view();
$("#a-fit", f).value = weights.fit;
@@ -531,7 +617,7 @@
$("#a-summarise-top", f).value = limits.summarise_top;
$("#a-summarise-min", f).value = limits.summarise_min;
$("#a-delete", f).hidden = !row;
f.addEventListener("input", () => { f.dataset.dirty = "true"; view(); offerEurope(); });
f.addEventListener("input", () => { f.dataset.dirty = "true"; view(); });
f.addEventListener("change", view);
f.addEventListener("submit", (event) => save(event, row, () => prompts.map((p) => p.read()), gates));
$("#a-cancel", f).addEventListener("click", () => { close(); render(); });
+9 -2
View File
@@ -1168,17 +1168,24 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
.rule-rows:empty, .prompt-rows:empty { display: none; }
.agent-form .rule-row input[type="text"] { flex: 1 1 8rem; width: auto; min-width: 0; }
.agent-form .rule-row input[type="number"], .agent-form .where input[type="number"] { width: 5rem; flex: none; }
/* A Where line: its words, then its chips, which wrap under them on a phone. */
/* A Where line: its words, then its chips, which wrap under them on a phone.
The words share one width, so the chips of every line start level. */
.where-line { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .9rem; }
.where-line > span { flex: none; }
.where-line > span, .where-line > label { flex: none; min-width: 9rem; }
.where-line .chips { flex: 1 1 12rem; }
/* 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; }
.agent-form .where-sum { margin: 0; padding-top: .5rem; border-top: 1px solid var(--line); font-size: .9rem; }
/* Values as the rail's tags, each removed by its ×; the box to add one takes
the rest of the line. */
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; min-width: 0; }
.agent-form .chips input[type="text"] { flex: 1 1 6rem; width: auto; min-width: 0; }
.agent-form .chips select { flex: 0 1 12rem; min-width: 0; max-width: 100%; }
.chips .tag span { color: var(--faint); }
.agent-form details summary { cursor: pointer; color: var(--dim); font-size: .9rem; }
.agent-form details[open] summary { margin-bottom: .5rem; }
.agent-form .advanced-body { display: flex; flex-direction: column; gap: .6rem; }
/* ================================================================ */
/* companies and sources — the Sources page's sections, */
+26 -20
View File
@@ -27,29 +27,27 @@
<span class="hint">A prompt is one kind of role in your own words: the work, the level, the setting. A role is ranked by the prompt it fits best, so three kinds of role are three prompts, not one blended paragraph. Votes and liked companies count for the whole agent.</span>
</fieldset>
<fieldset class="where">
<legend>Where</legend>
<legend>Where can the role be?</legend>
<span class="hint">A role passes when it matches any line; with none filled in, it can be anywhere. A role whose location is not known yet ranks until extract reads the posting.</span>
<div class="where-line">
<span>Only roles in</span>
<div id="a-in"></div>
<button type="button" id="a-europe" class="secondary">Europe</button>
<span>In these countries</span>
<div id="a-countries"></div>
</div>
<div class="where-line">
<span>and one of: in</span>
<div id="a-any-country"></div>
<span>In these towns</span>
<div id="a-towns"></div>
</div>
<label class="inline"><input type="checkbox" id="a-remote"> or remote</label>
<span class="hint">A town matches as part of the location, so Lund matches "Lund, Sweden": it is for towns outside the countries above.</span>
<div class="where-line">
<span>or in</span>
<div id="a-places"></div>
<label class="inline"><input type="checkbox" id="a-remote"> Remote</label>
<select id="a-remote-scope" aria-label="Remote from where">
<option value="europe">within Europe</option>
<option value="anywhere">anywhere</option>
</select>
</div>
<label class="inline"><input type="checkbox" id="a-hybrid"> Prefer hybrid, adding <input type="number" id="a-hybrid-weight" min="0" step="0.05" value="0.05" aria-label="Weight of hybrid"></label>
<span class="hint">Countries are ISO codes such as DK or SE, added with Enter or a comma; EU is a role open anywhere in Europe. Places are towns, matched as part of the location, so Lund matches "Lund, Sweden". An empty line is no rule. A rule only rejects a role whose column is filled; an empty one ranks until extract reads the posting.</span>
</fieldset>
<fieldset class="rules">
<legend>Other rules</legend>
<div id="a-rules" class="rule-rows"></div>
<button type="button" id="a-add-rule" class="secondary">Add rule</button>
<span class="hint">Must: a role must meet it. One of: a role must meet one of these and of the "one of" line above. Prefer: a role that meets it gains the weight. Values are separated by commas; salary is a number.</span>
<label class="inline where-rank"><input type="checkbox" id="a-hybrid"> Prefer hybrid<span id="a-hybrid-weight-line">, adding <input type="number" id="a-hybrid-weight" min="0" step="0.05" value="0.05" aria-label="Weight of hybrid"></span></label>
<span class="hint">This one ranks rather than filters: a hybrid role gains a little.</span>
<p id="a-where-sum" class="where-sum" role="status"></p>
</fieldset>
<fieldset class="weights">
<legend>How much each counts</legend>
@@ -68,9 +66,17 @@
<span class="hint">Every pull scores every open role for free; these bound what the model then reads, per agent. The count is the backstop, the score the real stop. Fit is a level, the same in every run: a new role with the worst fit scores about 0.27, a perfect one about 0.87. An agent with no prompt feeds neither stage.</span>
<details class="advanced">
<summary>Advanced</summary>
<label>Rules as sent
<textarea id="a-gates" class="code" rows="6" spellcheck="false" readonly>[]</textarea>
<span class="hint">Read only: what Save sends as the agent's gates, from Where and Other rules above.</span></label>
<div class="advanced-body">
<fieldset class="rules">
<legend>Other rules</legend>
<div id="a-rules" class="rule-rows"></div>
<button type="button" id="a-add-rule" class="secondary">Add rule</button>
<span class="hint">Must: a role must meet it. One of: a role must meet one of these or a Where line. Prefer: a role that meets it gains the weight. Values are separated by commas; salary is a number.</span>
</fieldset>
<label>Rules as sent
<textarea id="a-gates" class="code" rows="6" spellcheck="false" readonly>[]</textarea>
<span class="hint">Read only: what Save sends as the agent's gates, from Where and Other rules.</span></label>
</div>
</details>
<div class="agent-actions">
<button type="submit">Save and score</button>