The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(hermes_cli/web_routers): AST-neutral packing of literal dict/list spans
Tekniumec346c7521c6
diff --git a/hermes_cli/web_routers/actions.py b/hermes_cli/web_routers/actions.pyindex 3276a7e3a74..dca8bbd7b31 100644--- a/hermes_cli/web_routers/actions.py+++ b/hermes_cli/web_routers/actions.py@@ -224,21 +224,15 @@ async def gateway_drain(request: Request):def _update_refused(error: str, message: str, update_command: str) -> Dict[str, Any]:return {- "ok": False,- "pid": None,- "name": "hermes-update",- "error": error,- "message": message,+ "ok": False, "pid": None, "name": "hermes-update", "error": error, "message": message,"update_command": update_command,}# Per-kind dashboard error codes the UI keys on, by admission-refusal code._UPDATE_REFUSAL_ERROR_CODES = {- "docker": "docker_update_unsupported",- "image-marker": "docker_update_unsupported",- "image-marker-invalid": "docker_update_unsupported",- "apt": "apt_update_required",+ "docker": "docker_update_unsupported", "image-marker": "docker_update_unsupported",+ "image-marker-invalid": "docker_update_unsupported", "apt": "apt_update_required","nix": "nix_update_unsupported",}@@ -267,10 +261,7 @@ async def update_hermes():existing = _ACTION_PROCS.get("hermes-update")if existing is not None and existing.poll() is None:response = {- "ok": True,- "pid": existing.pid,- "name": "hermes-update",- "already_running": True,+ "ok": True, "pid": existing.pid, "name": "hermes-update", "already_running": True,}action_id = _ACTION_IDS.get("hermes-update")if action_id:@@ -300,13 +291,8 @@ def _recent_upstream_commits(n: int = 20) -> List[Dict[str, Any]]:try:out = subprocess.run([- "git",- "-C",- str(_project_root()),- "log",- "--format=%H%x1f%s%x1f%an%x1f%ct",- "HEAD..origin/main",- f"-n{int(n)}",+ "git", "-C", str(_project_root()), "log", "--format=%H%x1f%s%x1f%an%x1f%ct",+ "HEAD..origin/main", f"-n{int(n)}",],capture_output=True,text=True,@@ -352,26 +338,18 @@ async def check_hermes_update(force: bool = False):"""if _dashboard_local_update_managed_externally():return {- "install_method": "managed-runtime",- "current_version": __version__,- "behind": None,- "update_available": False,- "can_apply": False,- "update_command": "managed outside dashboard",- "message": _MANAGED_EXTERNALLY_MESSAGE,+ "install_method": "managed-runtime", "current_version": __version__, "behind": None,+ "update_available": False, "can_apply": False,+ "update_command": "managed outside dashboard", "message": _MANAGED_EXTERNALLY_MESSAGE,}install_method = detect_install_method(_project_root())update_command = recommended_update_command_for_method(install_method)payload: Dict[str, Any] = {- "install_method": install_method,- "current_version": __version__,- "behind": None,- "update_available": False,- "can_apply": install_method == "git",- "update_command": update_command,- "message": None,+ "install_method": install_method, "current_version": __version__, "behind": None,+ "update_available": False, "can_apply": install_method == "git",+ "update_command": update_command, "message": None,}if install_method == "docker":@@ -468,11 +446,7 @@ async def get_action_status(name: str, lines: int = 200):_finish_action(name, exit_code, pid)response = {- "name": name,- "running": running,- "exit_code": exit_code,- "pid": pid,- "lines": tail,+ "name": name, "running": running, "exit_code": exit_code, "pid": pid, "lines": tail,}if durable_update_action_id:response["action_id"] = durable_update_action_iddiff --git a/hermes_cli/web_routers/audio.py b/hermes_cli/web_routers/audio.pyindex 31b4bdc44c9..db0337c4ebd 100644--- a/hermes_cli/web_routers/audio.py+++ b/hermes_cli/web_routers/audio.py@@ -35,28 +35,16 @@ _ws_request_is_allowed = late("_ws_request_is_allowed")load_env = late("load_env")_AUDIO_MIME_EXTENSIONS: Dict[str, str] = {- "audio/aac": ".aac",- "audio/flac": ".flac",- "audio/m4a": ".m4a",- "audio/mp3": ".mp3",- "audio/mp4": ".mp4",- "audio/mpeg": ".mp3",- "audio/ogg": ".ogg",- "audio/wav": ".wav",- "audio/wave": ".wav",- "audio/webm": ".webm",- "audio/x-m4a": ".m4a",- "audio/x-wav": ".wav",+ "audio/aac": ".aac", "audio/flac": ".flac", "audio/m4a": ".m4a", "audio/mp3": ".mp3",+ "audio/mp4": ".mp4", "audio/mpeg": ".mp3", "audio/ogg": ".ogg", "audio/wav": ".wav",+ "audio/wave": ".wav", "audio/webm": ".webm", "audio/x-m4a": ".m4a", "audio/x-wav": ".wav","video/webm": ".webm",}_MAX_TRANSCRIPTION_UPLOAD_BYTES = 25 * 1024 * 1024_SPEAK_MIME_BY_EXT = {- ".mp3": "audio/mpeg",- ".ogg": "audio/ogg",- ".opus": "audio/ogg",- ".wav": "audio/wav",+ ".mp3": "audio/mpeg", ".ogg": "audio/ogg", ".opus": "audio/ogg", ".wav": "audio/wav",".flac": "audio/flac",}@@ -145,8 +133,7 @@ async def transcribe_audio_upload(raise HTTPException(status_code=400, detail=err)return {- "ok": True,- "transcript": str(result.get("transcript") or "").strip(),+ "ok": True, "transcript": str(result.get("transcript") or "").strip(),"provider": result.get("provider"),}@@ -254,8 +241,7 @@ async def get_elevenlabs_voices(profile: Optional[str] = None):continuevoices.append({- "voice_id": voice_id,- "name": str(voice.get("name") or voice_id),+ "voice_id": voice_id, "name": str(voice.get("name") or voice_id),"label": _elevenlabs_voice_label(voice),})@@ -315,9 +301,7 @@ async def speak_text(payload: TTSSpeakRequest, profile: Optional[str] = None):encoded = base64.b64encode(audio_bytes).decode("ascii")return {- "ok": True,- "data_url": f"data:{mime_type};base64,{encoded}",- "mime_type": mime_type,+ "ok": True, "data_url": f"data:{mime_type};base64,{encoded}", "mime_type": mime_type,"provider": result.get("provider"),}diff --git a/hermes_cli/web_routers/config_env.py b/hermes_cli/web_routers/config_env.pyindex 0d7e49b3675..4b7aa3fc47a 100644--- a/hermes_cli/web_routers/config_env.py+++ b/hermes_cli/web_routers/config_env.py@@ -144,13 +144,8 @@ async def update_config(body: ConfigUpdate, profile: Optional[str] = None):def _provider_card(d, description: str, url, *, is_password: bool, advanced: bool) -> dict:return {- "provider": d.slug,- "provider_label": d.label,- "description": description,- "url": url,- "is_password": is_password,- "advanced": advanced,- "category": "provider",+ "provider": d.slug, "provider_label": d.label, "description": description, "url": url,+ "is_password": is_password, "advanced": advanced, "category": "provider",}@@ -377,41 +372,28 @@ def _custom_endpoint_response(cfg: Dict[str, Any]) -> Dict[str, Any]:endpoint_model = str(raw_entry.get("model") or raw_entry.get("default_model") or (models[0] if models else ""))has_api_key, api_key_preview = _api_key_display(raw_entry)endpoints.append({- "id": endpoint_id,- "name": str(raw_entry.get("name") or endpoint_id),- "base_url": base_url,- "model": endpoint_model,- "models": models,+ "id": endpoint_id, "name": str(raw_entry.get("name") or endpoint_id),+ "base_url": base_url, "model": endpoint_model, "models": models,"context_length": raw_entry.get("context_length"),"discover_models": bool(raw_entry.get("discover_models", True)),- "has_api_key": has_api_key,- "api_key_preview": api_key_preview,- "is_current": endpoint_id == current_provider,- "source": "providers",+ "has_api_key": has_api_key, "api_key_preview": api_key_preview,+ "is_current": endpoint_id == current_provider, "source": "providers",})if current_provider.lower() == "custom" and current_base_url and not any(e["id"] == "custom" for e in endpoints):has_api_key, api_key_preview = _api_key_display(model_cfg)endpoints.insert(0, {- "id": "custom",- "name": "Custom",- "base_url": current_base_url,- "model": current_model,+ "id": "custom", "name": "Custom", "base_url": current_base_url, "model": current_model,"models": [current_model] if current_model else [],- "context_length": model_cfg.get("context_length"),- "discover_models": True,- "has_api_key": has_api_key,- "api_key_preview": api_key_preview,- "is_current": True,+ "context_length": model_cfg.get("context_length"), "discover_models": True,+ "has_api_key": has_api_key, "api_key_preview": api_key_preview, "is_current": True,"source": "direct-config",})return {"endpoints": endpoints,"current": {- "provider": current_provider,- "model": current_model,- "base_url": current_base_url,+ "provider": current_provider, "model": current_model, "base_url": current_base_url,},}@@ -465,9 +447,7 @@ def _write_custom_endpoint(cfg: Dict[str, Any], body: CustomEndpointUpdate) -> T# silently dropped them on an unrelated edit.entry: Dict[str, Any] = dict(existing)entry.update({- "name": name,- "base_url": base_url,- "model": model,+ "name": name, "base_url": base_url, "model": model,"discover_models": bool(body.discover_models),})# Same for the model map, so existing models keep their context lengths.diff --git a/hermes_cli/web_routers/memory_providers.py b/hermes_cli/web_routers/memory_providers.pyindex b2029e12d1e..a3e2568251b 100644--- a/hermes_cli/web_routers/memory_providers.py+++ b/hermes_cli/web_routers/memory_providers.py@@ -296,10 +296,7 @@ def _command_result(completed: Optional[subprocess.CompletedProcess] = None, error: Optional[str] = None,) -> Dict[str, Any]:return {- "kind": kind,- "name": name,- "status": status,- "command": command,+ "kind": kind, "name": name, "status": status, "command": command,"returncode": None if completed is None else completed.returncode,"stdout": "" if completed is None else _trim_setup_output(completed.stdout),"stderr": _trim_setup_output(error or ("" if completed is None else completed.stderr)),@@ -495,20 +492,13 @@ def _install_memory_provider_setup(name: str) -> Dict[str, Any]:def _public_memory_provider_field(field: Dict[str, Any], data: Dict[str, Any]) -> Dict[str, Any]:return {- "key": field["key"],- "label": field["label"],- "kind": field["kind"],- "description": field["description"],- "placeholder": field["placeholder"],+ "key": field["key"], "label": field["label"], "kind": field["kind"],+ "description": field["description"], "placeholder": field["placeholder"],"required": field["required"],"value": "" if field["kind"] == "secret" else _field_value(field, data),- "is_set": _field_is_set(field, data),- "options": field.get("options", []),- "url": field.get("url", ""),- "when": field.get("when"),- "minimum": field.get("minimum"),- "maximum": field.get("maximum"),- "step": field.get("step"),+ "is_set": _field_is_set(field, data), "options": field.get("options", []),+ "url": field.get("url", ""), "when": field.get("when"), "minimum": field.get("minimum"),+ "maximum": field.get("maximum"), "step": field.get("step"),}@@ -519,9 +509,7 @@ def _memory_provider_payload(name: str, provider: Any) -> Dict[str, Any]:for field in _normalize_memory_provider_schema(name, provider)]return {- "name": name,- "label": _memory_provider_label(name),- "fields": fields,+ "name": name, "label": _memory_provider_label(name), "fields": fields,"setup": _memory_provider_setup_info(name),}diff --git a/hermes_cli/web_routers/oauth.py b/hermes_cli/web_routers/oauth.pyindex 86d2cfe995e..221e343b11c 100644--- a/hermes_cli/web_routers/oauth.py+++ b/hermes_cli/web_routers/oauth.py@@ -195,11 +195,9 @@ def _codex_full_login_worker(session_id: str) -> None:token_resp = client.post(CODEX_OAUTH_TOKEN_URL,data={- "grant_type": "authorization_code",- "code": authorization_code,+ "grant_type": "authorization_code", "code": authorization_code,"redirect_uri": f"{issuer}/deviceauth/callback",- "client_id": CODEX_OAUTH_CLIENT_ID,- "code_verifier": code_verifier,+ "client_id": CODEX_OAUTH_CLIENT_ID, "code_verifier": code_verifier,},headers={"Content-Type": "application/x-www-form-urlencoded"},)@@ -239,8 +237,7 @@ def _codex_full_login_worker(session_id: str) -> None:def _nous_status(raw):# Refresh-free snapshot so listing providers never performs an OAuth refresh.return {- "logged_in": bool(raw.get("logged_in")),- "source": "nous_portal",+ "logged_in": bool(raw.get("logged_in")), "source": "nous_portal","source_label": raw.get("portal_base_url") or "Nous Portal","token_preview": _truncate_token(raw.get("access_token")),"expires_at": raw.get("access_expires_at"),@@ -250,20 +247,16 @@ def _nous_status(raw):def _codex_status(raw):return {- "logged_in": bool(raw.get("logged_in")),- "source": raw.get("source") or "openai_codex",+ "logged_in": bool(raw.get("logged_in")), "source": raw.get("source") or "openai_codex","source_label": raw.get("auth_mode") or "OpenAI Codex",- "token_preview": _truncate_token(raw.get("api_key")),- "expires_at": None,- "has_refresh_token": False,- "last_refresh": raw.get("last_refresh"),+ "token_preview": _truncate_token(raw.get("api_key")), "expires_at": None,+ "has_refresh_token": False, "last_refresh": raw.get("last_refresh"),}def _qwen_status(raw):return {- "logged_in": bool(raw.get("logged_in")),- "source": "qwen_cli",+ "logged_in": bool(raw.get("logged_in")), "source": "qwen_cli","source_label": raw.get("auth_store_path") or "Qwen CLI","token_preview": _truncate_token(raw.get("access_token")),"expires_at": raw.get("expires_at"),@@ -273,12 +266,9 @@ def _qwen_status(raw):def _minimax_status(raw):return {- "logged_in": bool(raw.get("logged_in")),- "source": "minimax_oauth",- "source_label": f"MiniMax ({raw.get('region', 'global')})",- "token_preview": None,- "expires_at": raw.get("expires_at"),- "has_refresh_token": True,+ "logged_in": bool(raw.get("logged_in")), "source": "minimax_oauth",+ "source_label": f"MiniMax ({raw.get('region', 'global')})", "token_preview": None,+ "expires_at": raw.get("expires_at"), "has_refresh_token": True,}@@ -286,13 +276,10 @@ def _xai_status(raw):# source_label is a human-readable origin (auth-store path / credential# source), not the internal auth_mode string ("oauth_pkce").return {- "logged_in": bool(raw.get("logged_in")),- "source": raw.get("source") or "xai_oauth",+ "logged_in": bool(raw.get("logged_in")), "source": raw.get("source") or "xai_oauth","source_label": raw.get("auth_store") or raw.get("source") or "xAI Grok OAuth",- "token_preview": _truncate_token(raw.get("api_key")),- "expires_at": None,- "has_refresh_token": True,- "last_refresh": raw.get("last_refresh"),+ "token_preview": _truncate_token(raw.get("api_key")), "expires_at": None,+ "has_refresh_token": True, "last_refresh": raw.get("last_refresh"),}@@ -373,12 +360,9 @@ async def _start_nous_device_code(profile: Optional[str]) -> Dict[str, Any]:)_start_poller(_nous_poller, sid)return {- "session_id": sid,- "flow": "device_code",- "user_code": str(device_data["user_code"]),+ "session_id": sid, "flow": "device_code", "user_code": str(device_data["user_code"]),"verification_url": str(device_data["verification_uri_complete"]),- "expires_in": int(device_data["expires_in"]),- "poll_interval": int(device_data["interval"]),+ "expires_in": int(device_data["expires_in"]), "poll_interval": int(device_data["interval"]),}@@ -402,11 +386,8 @@ async def _start_codex_device_code(profile: Optional[str]) -> Dict[str, Any]:if not s.get("user_code"):raise HTTPException(status_code=504, detail="device-auth timed out before returning a user code")return {- "session_id": sid,- "flow": "device_code",- "user_code": s["user_code"],- "verification_url": s["verification_url"],- "expires_in": int(s.get("expires_in") or 900),+ "session_id": sid, "flow": "device_code", "user_code": s["user_code"],+ "verification_url": s["verification_url"], "expires_in": int(s.get("expires_in") or 900),"poll_interval": int(s.get("interval") or 5),}@@ -453,11 +434,8 @@ async def _start_minimax_device_code(profile: Optional[str]) -> Dict[str, Any]:sess["expires_at"] = expires_at_ts_start_poller(_minimax_poller, sid)return {- "session_id": sid,- "flow": "device_code",- "user_code": str(device_data["user_code"]),- "verification_url": str(device_data["verification_uri"]),- "expires_in": expires_in_seconds,+ "session_id": sid, "flow": "device_code", "user_code": str(device_data["user_code"]),+ "verification_url": str(device_data["verification_uri"]), "expires_in": expires_in_seconds,"poll_interval": max(2, (sess["interval_ms"] or 2000) // 1000),}@@ -478,20 +456,15 @@ async def _start_xai_device_code(profile: Optional[str]) -> Dict[str, Any]:)_start_poller(_xai_device_poller, sid)return {- "session_id": sid,- "flow": "device_code",- "user_code": str(device_data["user_code"]),+ "session_id": sid, "flow": "device_code", "user_code": str(device_data["user_code"]),"verification_url": str(device_data.get("verification_uri_complete") or device_data["verification_uri"]),- "expires_in": int(device_data["expires_in"]),- "poll_interval": int(device_data["interval"]),+ "expires_in": int(device_data["expires_in"]), "poll_interval": int(device_data["interval"]),}_DEVICE_CODE_STARTERS = {- "nous": _start_nous_device_code,- "openai-codex": _start_codex_device_code,- "minimax-oauth": _start_minimax_device_code,- "xai-oauth": _start_xai_device_code,+ "nous": _start_nous_device_code, "openai-codex": _start_codex_device_code,+ "minimax-oauth": _start_minimax_device_code, "xai-oauth": _start_xai_device_code,}@@ -574,11 +547,8 @@ def _build_oauth_catalog() -> list[Dict[str, Any]]:continueseen.add(d.slug)rows.append({- "id": d.slug,- "name": d.label,- "flow": "external",- "cli_command": f"hermes auth add {d.slug}",- "docs_url": d.signup_url or "",+ "id": d.slug, "name": d.label, "flow": "external",+ "cli_command": f"hermes auth add {d.slug}", "docs_url": d.signup_url or "","status_fn": None,})except Exception:@@ -603,15 +573,11 @@ async def list_oauth_providers(profile: Optional[str] = None):status = _resolve_provider_status(p["id"], p.get("status_fn"))disconnect_hint = _oauth_provider_disconnect_hint(p, status)providers.append({- "id": p["id"],- "name": p["name"],- "flow": p["flow"],+ "id": p["id"], "name": p["name"], "flow": p["flow"],"cli_command": _external_process_cli_command(p["id"], p["cli_command"]),- "docs_url": p["docs_url"],- "disconnect_hint": disconnect_hint,+ "docs_url": p["docs_url"], "disconnect_hint": disconnect_hint,"disconnect_command": _oauth_provider_disconnect_command(p),- "disconnectable": disconnect_hint is None,- "status": status,+ "disconnectable": disconnect_hint is None, "status": status,})return {"providers": providers}@@ -769,10 +735,8 @@ async def poll_oauth_session(if sess.get("profile") != requested_profile:raise HTTPException(status_code=400, detail="OAuth session profile mismatch")return {- "session_id": session_id,- "status": sess["status"],- "error_message": sess.get("error_message"),- "expires_at": sess.get("expires_at"),+ "session_id": session_id, "status": sess["status"],+ "error_message": sess.get("error_message"), "expires_at": sess.get("expires_at"),}