feat: add conversation-scoped yolo controls

This commit is contained in:
2026-09-22 08:12:07 +00:00
parent b672762be8
commit 18c4b34d08
5 changed files with 218 additions and 2 deletions
+60
View File
@@ -686,6 +686,66 @@ async def resolve_clarify(clarify_id: str, response: str) -> bool:
return bool(ok)
# ═══════════════════════════════════════════════════════════════════════════
# Conversation-scoped YOLO / approval bypass
# ═══════════════════════════════════════════════════════════════════════════
async def yolo_snapshot(conversation_id: str) -> Dict[str, Any]:
"""Return the effective dangerous-command approval bypass for one chat."""
store = _session_store()
session_key = _session_key_for(conversation_id)
session_id = None
if store is not None:
try:
session_id = await asyncio.to_thread(store.peek_session_id, session_key)
except Exception:
logger.debug("[pheby] yolo session lookup failed", exc_info=True)
if not session_id:
return {"ok": False, "code": proto.ERR_CONVERSATION_NOT_FOUND,
"message": "Conversation not found"}
from tools.approval import enable_session_yolo, is_session_yolo_enabled
enabled = is_session_yolo_enabled(session_key)
if not enabled:
db = _session_db()
if db is not None:
try:
meta = await asyncio.to_thread(db.get_session, str(session_id))
from hermes_state import SessionDB
if SessionDB.session_yolo_enabled(meta):
enable_session_yolo(session_key)
enabled = True
except Exception:
logger.debug("[pheby] persisted yolo read failed", exc_info=True)
return {"ok": True, "enabled": bool(enabled), "scope": "conversation",
"conversation_id": conversation_id}
async def set_yolo(conversation_id: str, enabled: bool) -> Dict[str, Any]:
"""Set YOLO for one chat and persist it with that Hermes session."""
store = _session_store()
session_key = _session_key_for(conversation_id)
session_id = None
if store is not None:
try:
session_id = await asyncio.to_thread(store.peek_session_id, session_key)
except Exception:
logger.debug("[pheby] yolo session lookup failed", exc_info=True)
if not session_id:
return {"ok": False, "code": proto.ERR_CONVERSATION_NOT_FOUND,
"message": "Conversation not found"}
from tools.approval import disable_session_yolo, enable_session_yolo
(enable_session_yolo if enabled else disable_session_yolo)(session_key)
db = _session_db()
if db is not None:
try:
await asyncio.to_thread(db.set_session_yolo, str(session_id), bool(enabled))
except Exception:
logger.warning("[pheby] yolo persistence failed", exc_info=True)
return {"ok": True, "enabled": bool(enabled), "scope": "conversation",
"conversation_id": conversation_id}
# ═══════════════════════════════════════════════════════════════════════════
# Models & reasoning
# ═══════════════════════════════════════════════════════════════════════════