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

+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 };
})();