fix(cli): resolve -c by true MRU session

- order session listing by computed last_active in SessionDB so callers get MRU rows directly
- keep _resolve_last_session as a single-row lookup and add regression coverage for >20 session sampling
This commit is contained in:
Brooklyn Nicholson
2026-04-26 22:37:37 -05:00
committed by Teknium
parent 730347e38f
commit 164e33aa46
3 changed files with 157 additions and 6 deletions

View File

@@ -595,15 +595,14 @@ def _session_browse_picker(sessions: list) -> Optional[str]:
def _resolve_last_session(source: str = "cli") -> Optional[str]:
"""Look up the most recent session ID for a source."""
"""Look up the most recently-used session ID for a source."""
try:
from hermes_state import SessionDB
db = SessionDB()
sessions = db.search_sessions(source=source, limit=1)
db.close()
if sessions:
return sessions[0]["id"]
return sessions[0]["id"] if sessions else None
except Exception:
pass
return None