Files
hermes-agent/gateway/session_operator.py
yoniebans e09f4b7c47 refactor(gateway): session authority and gateway storage callers through the persistence interface
The gateway's session, authority, delivery and hosted-room modules call the interface operations instead of SessionDB and their own connections. The cron owner fake builds its authority on an interface handle, and the legacy cron run-history cases read the owner's store through a SessionDB of their own. The legacy tests whose cases the backend copies carry (journal mode, profile purge and rekey, owner reset housekeeping) go; the remaining legacy tests of these callers follow the moved names.
2026-11-17 17:51:21 +01:00

39 lines
2.0 KiB
Python

"""Private provenance for already-authorized operator input.
Operator access is profile-local, not account linking or a change of authorship.
It never claims unowned legacy history: that still requires the native migration
path. Only SessionAuthority.submit writes this envelope after authorization;
public submission parameters cannot supply it.
"""
from gateway.owner_identity import same_owner
from persistence.core.errors import AuthorityRefusal
# Fields ``SessionAuthority.submit`` commits for a local session's input; producers commit their own envelope.
LOCAL_INPUT_FIELDS = frozenset({'text', 'attachments_v1', 'finite', 'unattended', 'surface_v1', 'display_v1',
'cli_turn_v1', 'kanban_card_v1'})
def is_viewer_input(row):
"""A row a session viewer submitted through ``session.submit`` (a client's own prompt), not a producer
admission: ``local_automation_v1`` (plugin injection, delegation completions, process and watch notices,
/loop, heartbeat), a hosted-room task (``hosted:`` request id) or any other envelope."""
return (not str(row['request_id']).startswith('hosted:')
and {'text'} <= set(row['payload']) <= LOCAL_INPUT_FIELDS | {'local_operator_v1'})
def check_local_input(authority, ref, row, *, source=None):
payload = row['payload']
allowed = set(LOCAL_INPUT_FIELDS)
if 'local_operator_v1' in payload:
allowed.add('local_operator_v1')
if payload['local_operator_v1'] != {
'profile_id': authority.profile_id, 'session_id': ref.session_id,
'principal_id': row['principal_id']}:
raise AuthorityRefusal('permission_denied')
else:
source = source or authority.sessions[ref.session_id].source
if not same_owner(source.user_id, row['principal_id']): # the rule submit() stamped by
raise AuthorityRefusal('permission_denied')
if not {'text'} <= set(payload) <= allowed:
raise AuthorityRefusal('permission_denied')