session_info_reads.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Reports with no messaging handler that the shared gateway serves a local session itself.
  2. Main's classic CLI and its TUI slash worker printed `/toolsets` and `/platforms` from the process
  3. that held the agent. On the shared gateway that process is the owner, so ``slash.exec`` runs the
  4. classic CLI's own line builders (hermes_cli/cli_info_lines.py) here, inside the owning profile, for
  5. this session's toolsets: the same text on the classic CLI, Ink and every other local client.
  6. """
  7. from __future__ import annotations
  8. import asyncio
  9. def _toolsets(authority, policy):
  10. from hermes_cli.cli_info_lines import toolsets_lines
  11. return toolsets_lines(list(policy.current_toolsets(policy.config(authority, secrets=False))) if policy else [])
  12. def _platforms(authority, policy):
  13. from hermes_cli.cli_info_lines import platforms_lines
  14. return platforms_lines()
  15. READS = {'toolsets': _toolsets, 'platforms': _platforms}
  16. async def owner_lines(authority, lines, offload=None) -> dict:
  17. """``slash.exec``'s reply for ``lines()``, built off the owner loop in the owning profile, on
  18. ``offload`` (an awaitable executor hop) or else the loop's default pool."""
  19. from gateway.session_authorities import owner_scope
  20. def build():
  21. with owner_scope(authority):
  22. return '\n'.join(lines()).strip('\n')
  23. return {'type': 'exec', 'output': await (offload or asyncio.to_thread)(build)}
  24. async def run_info_read(authority, live, name) -> dict:
  25. """Render *name* off the owner loop, in the owning profile; None policy = no frozen route."""
  26. from gateway.session_policy import policy_for_source
  27. policy = policy_for_source(authority.runner, live.source)
  28. return await owner_lines(authority, lambda: READS[name](authority, policy))