Files
gabrielvidalandClaude Opus 5.5 2037700317 feat(plugins): retire core Context & skills dashboard into the context-skills plugin (contextcost.read bridge, /dashboards grid)
- GET /api/dashboard → owner-only contextcost.read bridge (plugins/hubcontextcost.py)
- /dashboards becomes DashboardsHome, a card grid of the dashboard plugins' pages
- one-time carry-over of the stat-card order/bench into the plugin's layout.json
- telemetry: /dashboards is dash.home; the plugin page keeps dash.overview

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 13:48:04 +01:00

65 lines
2.5 KiB
Python

"""The *Context & skills* dashboard's saved stat-card layout → the
``context-skills`` plugin (2026-11-28).
The core page kept the owner's arrangement of its six stat cards in the
settings blob (``ui-state`` ``ai-agent-settings`` → ``state.listOrders
["dashboard-stats"]`` and ``state.listStashes["dashboard-stats"]``, card ids
``cost`` ``tokens`` ``files`` ``skills`` ``invocations`` ``skillSpend``). The
plugin keeps it in the owner's ``layout.json`` (``{"order": [...], "bench":
[...]}``, the same ids). Copied once, when the owner arranged anything and the
plugin has no layout yet — it needs no install (it only writes the owner's
data dir for the plugin); a ``.carried-over`` marker in the plugin's shared
dir makes it run once. The blob keeps its keys, unread.
"""
from __future__ import annotations
import json
import logging
from plugins.store import OWNER_UID, PluginStore
log = logging.getLogger(__name__)
PLUGIN = "context-skills"
LIST = "dashboard-stats"
CARDS = ("cost", "tokens", "files", "skills", "invocations", "skillSpend")
def _ids(v) -> list[str]:
out: list[str] = []
for x in v if isinstance(v, list) else []:
if isinstance(x, str) and x in CARDS and x not in out:
out.append(x)
return out
def layout(store: PluginStore | None, ui_state) -> bool:
"""Carry the owner's stat-card layout over; True when it wrote one."""
if store is None or ui_state is None:
return False
try:
marker = store.shared_data_dir(PLUGIN) / ".carried-over"
if marker.exists():
return False
moved = False
raw = ui_state.get("ai-agent-settings")
try:
blob = json.loads(raw) if raw else None
except ValueError:
blob = None
state = (blob or {}).get("state") if isinstance(blob, dict) else None
if isinstance(state, dict):
order = _ids((state.get("listOrders") or {}).get(LIST))
bench = [i for i in _ids((state.get("listStashes") or {}).get(LIST)) if i not in order]
dst = store.user_data_dir(OWNER_UID, PLUGIN) / "layout.json"
if (order or bench) and not dst.exists():
dst.write_text(json.dumps({"order": order, "bench": bench}))
moved = True
log.info("context-skills: carried the dashboard's stat-card layout over")
marker.write_text("1")
return moved
except Exception as e: # noqa: BLE001 — never stop the boot; the next start retries
log.warning("context-skills carry-over: %s", e)
return False