- frontend: drop the dead Conversations dashboard code (costAnalysis, DashboardFilters, ConversationsDashboard), the unused analytics / footprint / pricing helpers, the orphan api.ts comment and the dead mocks (perf dashboard, storage dashboard, telemetry hub/usage, usage daily/history/calibration); their French strings - backend: drop look.parse_action (the conversation-labels plugin has its own) and UsersStore.emails() (no caller) - routes: drop GET /api/usage/daily|history|calibration, GET /api/telemetry/usage, GET /api/goals, POST /api/goal-work — the plugin bridges call daily_usage, calibrate.history, views.usage, goals_list and goal_work directly; authz table + golden matrix updated; openapi.json re-dumped, src/generated regenerated - FALLBACK_ACCOUNTS: one neutral Claude seat instead of a stale copy of the providers' profiles (the full list moves to mock/accounts.ts) - notify CLI: no local PRICES estimate — the line is "Claude Code · 78k tokens · 8m" and the hub's restate_cost puts the run's exact list price in (an older CLI's $ line is still restated) - CLAUDE.md / docs / docstrings: scheduled/, templates/, sidecar *_usage.py, the clarifier (now the plugin's agents[] + prefs), runs/extras.py, sidecar/routes_chrome.py Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
4.3 KiB
Python
102 lines
4.3 KiB
Python
"""What a claude run is launched with on top of its prompt: an appended system
|
|
prompt and subagent definitions (``claude --agents``).
|
|
|
|
* every run — the live plugins' subagents (``agents[]`` in ``plugin.json``,
|
|
``plugins/agents.py``), such as the ``clarifier`` plugin's, which asks the
|
|
user a form so the main thread doesn't carry it — each with its person's
|
|
plugin prefs (model, effort, on/off);
|
|
* a lab run (not a guest's) — the homelab agents marked ``portable: true``
|
|
(workers/labsync.py), whatever the run's cwd. A worker gets those as files
|
|
through the lab sync instead, so its runs carry nothing extra.
|
|
|
|
The sidecar caps the ``--agents`` payload; an older one at 5 agents / 16 000
|
|
chars, a newer one says its own limits in ``/health`` (``agentsMax``). The
|
|
plugin subagents come first; a portable agent that doesn't fit the rest of the
|
|
budget is left out of that run.
|
|
|
|
(Work runs used to get a Haiku ``work-context`` agent here, rendered from the
|
|
profile's resources block. Since 2026-11-05 it lives on the Orus MacBook
|
|
itself — an opt-in ``~/.claude/agents/work-context.md`` — and the hub injects
|
|
nothing work-specific.)
|
|
|
|
It also refuses a definition key it doesn't know (400, the whole run). One
|
|
from 2026-11-04 on lists the keys it takes in ``/health`` (``agentKeys``, the
|
|
lab's read here, a worker's from its last probe); a definition sent to one
|
|
that doesn't list them loses ``omitClaudeMd`` / ``effort`` — the clarifier as
|
|
it was — rather than the run failing until that worker updates.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import time
|
|
|
|
from plugins import agents as plugin_agents
|
|
from workers import labsync
|
|
|
|
OLD_MAX = {"count": 5, "chars": 16000}
|
|
# The definition keys every sidecar takes (one without ``agentKeys`` in /health).
|
|
OLD_KEYS = frozenset({"description", "prompt", "model", "tools", "disallowedTools"})
|
|
_health: list = [0.0, None] # [fetched at, {"budget", "keys"}]
|
|
|
|
|
|
def _lab_health() -> dict:
|
|
"""The host sidecar's ``agentsMax`` and ``agentKeys`` (cached a minute)."""
|
|
from runs.sidecar_client import _sidecar_get
|
|
if time.time() - _health[0] > 60 or _health[1] is None:
|
|
h = _sidecar_get("/health", timeout=3) or {}
|
|
m = h.get("agentsMax")
|
|
ok = isinstance(m, dict) and all(isinstance(m.get(k), int) for k in OLD_MAX)
|
|
_health[:] = [time.time(), {"budget": {k: m[k] for k in OLD_MAX} if ok else dict(OLD_MAX),
|
|
"keys": _keys(h.get("agentKeys"))}]
|
|
return _health[1]
|
|
|
|
|
|
def _lab_budget() -> dict:
|
|
return _lab_health()["budget"]
|
|
|
|
|
|
def _keys(raw) -> frozenset:
|
|
"""A sidecar's ``agentKeys`` — the old set when it says none."""
|
|
if isinstance(raw, list) and all(isinstance(k, str) for k in raw):
|
|
return frozenset(raw) | OLD_KEYS
|
|
return OLD_KEYS
|
|
|
|
|
|
def _accepted(agents: dict, keys: frozenset) -> dict:
|
|
"""Each definition without the keys the target sidecar would refuse."""
|
|
return {name: {k: v for k, v in d.items() if k in keys} for name, d in agents.items()}
|
|
|
|
|
|
def _fit(agents: dict, extra: dict, budget: dict) -> dict:
|
|
"""``agents`` plus as many of ``extra`` (in order) as the budget holds."""
|
|
out = dict(agents)
|
|
for name, d in extra.items():
|
|
if name in out:
|
|
continue
|
|
trial = {**out, name: d}
|
|
if len(trial) > budget["count"] or len(json.dumps(trial)) > budget["chars"]:
|
|
continue
|
|
out = trial
|
|
return out
|
|
|
|
|
|
def run_extras(deps, account: str | None, worker: str | None,
|
|
cwd: str | None, *, scoped: bool = False,
|
|
person: str | None = None) -> dict:
|
|
"""``{appendSystemPrompt?, agents?}`` for a claude run (``{}`` = none).
|
|
``scoped``: a guest's run (gets active plugin subagents only, e.g. the
|
|
``clarifier`` plugin). ``person``: whom the run is for (``runAs``) — their
|
|
own plugin preferences on top of the operator's defaults."""
|
|
out: dict = {}
|
|
agents = dict(plugin_agents.agent_definitions_for(deps, person))
|
|
if not worker and not scoped:
|
|
portable = labsync.agent_definitions()
|
|
if portable:
|
|
agents = _fit(agents, portable, _lab_budget())
|
|
if agents:
|
|
keys = (_keys(deps.worker_store.status(worker).get("agentKeys")) if worker
|
|
else _lab_health()["keys"])
|
|
out["agents"] = _accepted(agents, keys)
|
|
return out
|