The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat: expose authenticated owner mutation snapshots
Tekniumd6331c4813ba
diff --git a/hermes_cli/web_routers/sessions.py b/hermes_cli/web_routers/sessions.pyindex b78946a2d19..0ade6726cfd 100644--- a/hermes_cli/web_routers/sessions.py+++ b/hermes_cli/web_routers/sessions.py@@ -482,6 +482,18 @@ async def get_session_detail(session_id: str, profile: Optional[str] = None):return _with_db(profile, _detail, read_only=True)+@manage_router.get("/api/sessions/{session_id}/mutation-snapshot")+async def get_session_mutation_snapshot(session_id: str, request: Request, profile: Optional[str] = None):+ from hermes_cli.web_server_sessions import _session_mutation_context+ authority, _actor = _session_mutation_context(request, profile)+ row = authority.db.get_session(session_id)+ # An absent import anchor has revision zero by the owner's storage contract,+ # not by a client guessing after a failed or stale detail request.+ return {'session_id': session_id, 'exists': row is not None,+ 'runtime_revision': row['runtime_revision'] if row else 0,+ 'runtime_generation': row['runtime_generation'] if row else None}++@manage_router.get("/api/sessions/{session_id}/latest-descendant")async def get_session_latest_descendant(session_id: str, profile: Optional[str] = None):latest, path = await asyncio.to_thread(diff --git a/hermes_cli/web_server_sessions.py b/hermes_cli/web_server_sessions.pyindex e9bd24c9f58..44b49fecefa 100644--- a/hermes_cli/web_server_sessions.py+++ b/hermes_cli/web_server_sessions.py@@ -66,17 +66,13 @@ def _session_latest_descendant(session_id: str, db):return current, path-async def _mutate_session_request(request, profile, session_id, *, request_id,- expected_revision, operation, payload, expected_generation=None):- """Resolve the authenticated principal and owner; never open a second writer."""+def _session_mutation_context(request, profile):+ """Use the same principal and profile boundary for prepare and apply."""from fastapi import HTTPException- from gateway.session_contract import Principal, SessionRef- from gateway.session_mutations import mutate_session- from hermes_state_runtime import RuntimeStoreError+ from gateway.session_contract import Principalfrom hermes_cli.web_server import _has_valid_session_tokenfrom hermes_cli.web_server_cron import _cron_profile_homefrom hermes_state import _default_db_path- import sqlite3native = getattr(request.state, 'native_http_principal', None)session = getattr(request.state, 'session', None)@@ -96,14 +92,26 @@ async def _mutate_session_request(request, profile, session_id, *, request_id,raise HTTPException(status_code=403, detail='profile_mismatch')if native is not None and native['profile_id'] != authority.profile_id:raise HTTPException(status_code=403, detail='profile_mismatch')+ return authority, Principal(subject, authority.profile_id,+ frozenset({'session:read', 'session:control', 'session:create'}), 'http')+++async def _mutate_session_request(request, profile, session_id, *, request_id,+ expected_revision, operation, payload, expected_generation=None):+ """Resolve the authenticated principal and owner; never open a second writer."""+ import sqlite3+ from fastapi import HTTPException+ from gateway.session_contract import SessionRef+ from gateway.session_mutations import mutate_session+ from hermes_state_runtime import RuntimeStoreError++ authority, actor = _session_mutation_context(request, profile)if operation == 'import':_, errors = authority.db._validate_import_payload(payload['sessions'])if errors:raise HTTPException(status_code=400, detail={'errors': errors})if request_id is None or expected_revision is None:raise HTTPException(status_code=409, detail='mutation_identity_required')- actor = Principal(subject, authority.profile_id,- frozenset({'session:read', 'session:control', 'session:create'}), 'http')params = dict(session_id=session_id, request_id=request_id, expected_revision=expected_revision,operation=operation, payload=payload)if expected_generation is not None: