Offer only the remote tokens within the asking agent's scope, so an agent kept to Europe is not offered Remote · United States

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 16:27:09 +02:00
1 parent 5c3c187dca
commit 9e2631ffe3
3 files changed
+44 -9

No files matched your search

+14 -6
View File
@@ -738,7 +738,8 @@ def _asks_remote(text: str) -> tuple[bool, str]:
def _remote_suggestions(text: str, gaz: Gazetteer,
areas: list[tuple[tuple[int, ...], int]]) -> list[Suggestion]:
areas: list[tuple[tuple[int, ...], int]],
scope: Iterable[int] = ()) -> list[Suggestion]:
"""`remote:` tokens for typed text, each with the open remote roles it
finds (`Gazetteer.overlap`, which holds Anywhere), none that finds
nothing, widest first and then by open roles. A place is offered when it
@@ -746,7 +747,10 @@ def _remote_suggestions(text: str, gaz: Gazetteer,
(`held`). "remote" alone offers every continent and country held;
"remote den" or "den" the places offered whose name it starts, a region
or a town only when its token names it alone. `remote:anywhere` is a
token and no suggestion: every remote chip holds Anywhere already."""
token and no suggestion: every remote chip holds Anywhere already. With
a `scope`, the places of the asking agent's `require` gates on country,
only a place in the scope or one the scope lies in is offered, so an
agent kept to Europe is not offered Remote · United States."""
asked, text = _asks_remote(text)
held: set[int] = set()
for ids, _ in areas:
@@ -759,6 +763,8 @@ def _remote_suggestions(text: str, gaz: Gazetteer,
if (place.kind in _WIDE or p in held) and _prefixes(text, gaz.names(p))}
else:
candidates = set()
if scope := set(scope):
candidates &= gaz.under(scope) | {a for p in scope for a in gaz.ancestors(p)}
found: dict[str, tuple[int, Suggestion]] = {}
for place_id in candidates - {gaz.anywhere}:
token = parse(f"remote:{gaz.token(place_id)}")
@@ -776,7 +782,8 @@ def _remote_suggestions(text: str, gaz: Gazetteer,
def suggest(q: str, places: Iterable[tuple[str, str, int]], limit: int = 12,
remote: Iterable[tuple[Iterable[int], int]] = (),
gaz: Gazetteer | None = None,
remote_any: Callable[[], int] | None = None) -> list[Suggestion]:
remote_any: Callable[[], int] | None = None,
scope: Iterable[int] = ()) -> list[Suggestion]:
"""Tokens for the text typed so far. `places` is `(place, country, open
roles)`, `remote` is `(area, open roles)` for the open remote roles, the
area as place ids of `gaz`, and `remote_any` counts the open roles
@@ -791,7 +798,8 @@ def suggest(q: str, places: Iterable[tuple[str, str, int]], limit: int = 12,
a line, grouped by fold and by alias (`Copenhagen` and `København` are one
town, shown as its commonest spelling). Countries, regions and towns with no
open role are left out: a chip that finds nothing helps nobody. Remote
tokens are `_remote_suggestions`, offered only with `gaz`."""
tokens are `_remote_suggestions`, offered only with `gaz` and kept to
`scope` when one is given."""
text = fold(q)
if not text:
return []
@@ -837,8 +845,8 @@ def suggest(q: str, places: Iterable[tuple[str, str, int]], limit: int = 12,
else _TOWN_LABELS.get(group) or group.title()
towns.append(Suggestion(f"place:{fold(shown)}", shown, "place", total))
remotes = _remote_suggestions(text, gaz, [(tuple(ids), int(n)) for ids, n in remote]) \
if gaz is not None else []
remotes = _remote_suggestions(text, gaz, [(tuple(ids), int(n)) for ids, n in remote],
scope) if gaz is not None else []
first = []
if remote_any is not None and _asks_remote(text)[0] and (count := remote_any()):
first.append(Suggestion("remote:any", "Remote", "remote", count))
+9 -3
View File
@@ -345,15 +345,21 @@ def suggest_places(
regions, then towns, each by open roles (`places.suggest`, over every
open role's place line and every open remote role's area). The count of
`remote:any` is the remote roles in the scope of `agent`, the default
agent when absent, as the feed counts them. An empty `q` suggests
nothing."""
agent when absent, as the feed counts them, and the other remote tokens
are kept to that agent's scope, its `require` gates on country. An empty
`q` suggests nothing."""
if not places.fold(q):
return []
viewer = _agent_id(store, agent)
gaz = store.gazetteer()
found = store.agent(viewer) if viewer is not None else None
scope = {p for g in (found.gates if found is not None else ())
if g.field == "country" and g.mode == "require"
for v in g.values for p in gaz.lookup(f"country:{v}") or ()}
return [PlaceSuggestion(token=s.token, label=s.label, kind=s.kind, count=s.count)
for s in places.suggest(
q, store.open_places(), limit, remote=store.open_remote_areas(),
gaz=store.gazetteer(),
gaz=gaz, scope=scope,
remote_any=lambda: store.count_roles(places=["remote:any"], agent=viewer,
by_score=False))]