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 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 15:31:40 +02:00
1 parent 1c7bc72198
commit 888586c29b
5 files changed
+179 -95

No files matched your search

+49 -28
View File
@@ -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.";
};
+47 -29
View File
@@ -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 };
})();
+10 -4
View File
@@ -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) });
+17 -2
View File
@@ -29,6 +29,16 @@
<fieldset class="where">
<legend>Where can the role be?</legend>
<span class="hint">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.</span>
<div class="where-line">
<span>Only roles in:</span>
<select id="a-scope" aria-label="Only roles in">
<option value="europe">Europe</option>
<option value="countries">Chosen countries</option>
<option value="everywhere">Everywhere</option>
</select>
<div id="a-scope-countries"></div>
</div>
<span class="hint">Every role must be in this, whatever the lines below add. A company set to All countries is read within this.</span>
<div class="where-line">
<span>Anywhere in</span>
<div id="a-countries"></div>
@@ -39,10 +49,15 @@
</div>
<span class="hint">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.</span>
<div class="where-line">
<span>Remote, open to someone in:</span>
<span>Remote:</span>
<select id="a-remote" aria-label="Remote">
<option value="none">no</option>
<option value="scope">anywhere within the scope</option>
<option value="from">only when open to someone in:</option>
</select>
<div id="a-remote-from"></div>
</div>
<span class="hint">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.</span>
<span class="hint">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.</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>
+56 -32
View File
@@ -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]);
});