Skip to content

The agent that grows with you

refactor(cli): build the surface groups once at import

kshitijk4poora913b2197321
diff --git a/gateway/session_policy.py b/gateway/session_policy.py
index f28538a7932..b711745cc8a 100644
--- a/gateway/session_policy.py
+++ b/gateway/session_policy.py
@@ -96,18 +96,11 @@ def created_surface(label):
return SURFACES[label] if label in STORED_AS_LOCAL else label
-def surface_groups():
- """Policy label and agent surface for one conversation, keyed by either name.
-
- ``--source gui`` and ``--source desktop`` are the same rows. ``tool`` and
- ``oneshot`` are not aliases of ``cli`` here: they keep their own stored label.
- """
- groups = {}
- for label in STORED_AS_LOCAL:
- group = frozenset({label, SURFACES[label]})
- for name in group:
- groups[name] = group
- return groups
+# Policy label and agent surface for one conversation, keyed by either name: ``--source gui``
+# and ``--source desktop`` are the same rows. ``tool`` and ``oneshot`` are not aliases of
+# ``cli`` here: they keep their own stored label.
+SURFACE_GROUPS = {name: group for group in (frozenset({label, SURFACES[label]}) for label in STORED_AS_LOCAL)
+ for name in group}
def _refuse(field, detail=None):
diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.py
index b43a6f77689..66daacf4b38 100644
--- a/hermes_cli/gateway_session_store.py
+++ b/hermes_cli/gateway_session_store.py
@@ -404,10 +404,6 @@ class SurfaceLabelReader:
self._has_column = any(row[1] == "created_source" for row in rows)
return self._has_column
- def _groups(self):
- from gateway.session_policy import surface_groups
- return surface_groups()
-
def _expand(self, requested):
"""``(live source labels, created_source labels)`` or None for a raw source filter.
@@ -417,10 +413,11 @@ class SurfaceLabelReader:
name of a gui/desktop pair, so a row that has not been peer-refreshed (``source='gui'``)
still matches ``--source desktop``.
"""
+ from gateway.session_policy import SURFACE_GROUPS
wanted = {requested} if isinstance(requested, str) else set(requested or ())
created = set()
live = set(wanted)
- for name, group in self._groups().items():
+ for name, group in SURFACE_GROUPS.items():
if name in wanted:
live |= group
created |= group