refactor(web-profiles/status): AST-neutral bracket packing/hugging
This commit is contained in:
@@ -434,12 +434,9 @@ def get_profiles_sessions(
|
||||
# section passes source=cron — two independent lists so newest cron sessions can't
|
||||
# starve the recents page.
|
||||
filters = dict(
|
||||
source=source or None,
|
||||
sources=_csv_list(sources) or None,
|
||||
exclude_sources=_csv_list(exclude_sources) or None,
|
||||
min_message_count=max(0, min_messages),
|
||||
include_archived=archived == "include",
|
||||
archived_only=archived == "only")
|
||||
source=source or None, sources=_csv_list(sources) or None,
|
||||
exclude_sources=_csv_list(exclude_sources) or None, min_message_count=max(0, min_messages),
|
||||
include_archived=archived == "include", archived_only=archived == "only")
|
||||
# Over-fetch per profile so the merged+sorted window is correct for the requested page.
|
||||
# Capped so a huge profile can't blow up the response.
|
||||
per_profile = min(max(limit + offset, limit), 500)
|
||||
@@ -470,12 +467,8 @@ def get_profiles_sessions(
|
||||
@sessions_router.get("/api/profiles/sessions/sidebar")
|
||||
@_sidebar_singleflight_cache
|
||||
def get_profiles_sessions_sidebar(
|
||||
recents_profile: str = "all",
|
||||
recents_limit: int = 20,
|
||||
recents_exclude: str = None,
|
||||
cron_limit: int = 50,
|
||||
messaging_limit: int = 100,
|
||||
messaging_exclude: str = None):
|
||||
recents_profile: str = "all", recents_limit: int = 20, recents_exclude: str = None,
|
||||
cron_limit: int = 50, messaging_limit: int = 100, messaging_exclude: str = None):
|
||||
"""Batched sidebar session slices — one profile-DB open per refresh.
|
||||
|
||||
The desktop sidebar needs three source-scoped windows per refresh: recents (local
|
||||
@@ -590,9 +583,7 @@ def _merge_by_id(into: Dict[str, Dict[str, Any]], entries: List[Dict[str, Any]],
|
||||
|
||||
|
||||
def _merge_profile_tree(
|
||||
merged: Dict[str, Dict[str, Any]],
|
||||
projects: List[Dict[str, Any]],
|
||||
profile: str,
|
||||
merged: Dict[str, Dict[str, Any]], projects: List[Dict[str, Any]], profile: str,
|
||||
preview_limit: int) -> None:
|
||||
"""Fold one profile's projects into the shared tree, keyed by folder.
|
||||
|
||||
|
||||
@@ -319,7 +319,8 @@ def _auth_gate_status() -> Dict[str, Any]:
|
||||
except Exception:
|
||||
# Module not importable yet (early startup) — leave as [].
|
||||
pass
|
||||
return {"auth_required": auth_required, "auth_providers": auth_providers, "auth_flows": auth_flows}
|
||||
return {"auth_required": auth_required, "auth_providers": auth_providers,
|
||||
"auth_flows": auth_flows}
|
||||
|
||||
|
||||
def _nous_session_validity() -> str:
|
||||
@@ -465,7 +466,8 @@ async def get_status(profile: Optional[str] = None):
|
||||
"gateway_updated_at": gateway["gateway_updated_at"],
|
||||
"active_agents": active_agents,
|
||||
"gateway_busy": derive_gateway_busy(
|
||||
gateway_running=gateway_running, gateway_state=gateway_state, active_agents=active_agents),
|
||||
gateway_running=gateway_running, gateway_state=gateway_state,
|
||||
active_agents=active_agents),
|
||||
"gateway_drainable": derive_gateway_drainable(
|
||||
gateway_running=gateway_running, gateway_state=gateway_state),
|
||||
"restart_drain_timeout": restart_drain_timeout,
|
||||
@@ -521,9 +523,7 @@ async def get_system_stats():
|
||||
|
||||
info: Dict[str, Any] = {
|
||||
**_display_system_platform(
|
||||
system=_platform.system(),
|
||||
release=_platform.release(),
|
||||
version=_platform.version(),
|
||||
system=_platform.system(), release=_platform.release(), version=_platform.version(),
|
||||
platform_label=_platform.platform()),
|
||||
"arch": _platform.machine(),
|
||||
"hostname": _platform.node(),
|
||||
@@ -554,7 +554,8 @@ async def get_system_stats():
|
||||
def _process():
|
||||
proc = psutil.Process()
|
||||
info["process"] = {"pid": proc.pid, "rss": proc.memory_info().rss,
|
||||
"create_time": int(proc.create_time()), "num_threads": proc.num_threads()}
|
||||
"create_time": int(proc.create_time()),
|
||||
"num_threads": proc.num_threads()}
|
||||
|
||||
# psutil enriches the picture when present; everything below is optional.
|
||||
try:
|
||||
@@ -664,7 +665,8 @@ async def get_learning_node(id: str, profile: Optional[str] = None):
|
||||
async def delete_learning_node(body: LearningNodeRef):
|
||||
"""Delete a journey node — skills are archived (restorable), memories removed."""
|
||||
from agent.learning_mutations import delete_node
|
||||
return await _learning_mutation(body.profile, lambda: delete_node(body.id), 400, "delete failed")
|
||||
return await _learning_mutation(
|
||||
body.profile, lambda: delete_node(body.id), 400, "delete failed")
|
||||
|
||||
|
||||
@router.put("/api/learning/node")
|
||||
@@ -794,11 +796,8 @@ async def run_debug_share_endpoint(body: DebugShareRequest | None = None):
|
||||
|
||||
@logs_router.get("/api/logs")
|
||||
async def get_logs(
|
||||
file: str = "agent",
|
||||
lines: int = 100,
|
||||
level: Optional[str] = None,
|
||||
component: Optional[str] = None,
|
||||
search: Optional[str] = None):
|
||||
file: str = "agent", lines: int = 100, level: Optional[str] = None,
|
||||
component: Optional[str] = None, search: Optional[str] = None):
|
||||
from hermes_cli.logs import _read_tail, LOG_FILES
|
||||
|
||||
log_name = LOG_FILES.get(file)
|
||||
@@ -829,10 +828,8 @@ async def get_logs(
|
||||
|
||||
has_filters = bool(min_level or comp_prefixes or search)
|
||||
result = _read_tail(
|
||||
log_path, min(lines, 500) if not search else 2000,
|
||||
has_filters=has_filters,
|
||||
min_level=min_level,
|
||||
component_prefixes=comp_prefixes)
|
||||
log_path, min(lines, 500) if not search else 2000, has_filters=has_filters,
|
||||
min_level=min_level, component_prefixes=comp_prefixes)
|
||||
# _read_tail doesn't support free-text search, so post-filter (case-insensitive
|
||||
# substring) here and trim to the requested line count afterward.
|
||||
if search:
|
||||
|
||||
@@ -116,8 +116,8 @@ def _fallback_profile_entry(profiles_mod, name: str, home: Path, *, is_default:
|
||||
return _safe(lambda: profiles_mod.read_profile_meta(home).get(key, default), default)
|
||||
|
||||
return {
|
||||
"name": name, "path": str(home), "is_default": is_default, "model": model, "provider": provider,
|
||||
"has_env": has_env,
|
||||
"name": name, "path": str(home), "is_default": is_default,
|
||||
"model": model, "provider": provider, "has_env": has_env,
|
||||
"skill_count": _safe(lambda: profiles_mod._count_skills(home), 0),
|
||||
"gateway_running": _safe(gateway_running, False),
|
||||
"description": meta("description", ""), "description_auto": meta("description_auto", False),
|
||||
@@ -422,9 +422,11 @@ def _installed_hub_identifiers(profile: Optional[str] = None) -> dict:
|
||||
if _is_current_profile(profile):
|
||||
lock = HubLockFile()
|
||||
else:
|
||||
lock = HubLockFile(_resolve_profile_dir(profile.strip()) / "skills" / ".hub" / "lock.json")
|
||||
profile_dir = _resolve_profile_dir(profile.strip())
|
||||
lock = HubLockFile(profile_dir / "skills" / ".hub" / "lock.json")
|
||||
return {
|
||||
entry["identifier"]: {"name": entry.get("name"), "trust_level": entry.get("trust_level"),
|
||||
entry["identifier"]: {"name": entry.get("name"),
|
||||
"trust_level": entry.get("trust_level"),
|
||||
"scan_verdict": entry.get("scan_verdict")}
|
||||
for entry in lock.list_installed() if entry.get("identifier")}
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user