Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(diagnostics): share-safe cross-device setup report endpoint
Ruben Lütkedaf30ba2e190
diff --git a/jarvis/ui/web/server.py b/jarvis/ui/web/server.pyindex 575e3a3dab..931e57dafa 100644--- a/jarvis/ui/web/server.py+++ b/jarvis/ui/web/server.py@@ -320,6 +320,7 @@ class WebServer:from .self_mod_routes import router as self_mod_routerfrom .sessions_routes import router as sessions_routerfrom .settings_routes import router as settings_router+ from .setup_report_routes import router as setup_report_routerfrom .setup_routes import router as setup_routerfrom .skills_routes import router as skills_routerfrom .socials_routes import router as socials_router@@ -357,6 +358,9 @@ class WebServer:# In-app updater (GET status / POST apply). Managed-install only — see# jarvis/ui/web/update_routes.py; refuses to self-reset a dev checkout.app.include_router(update_router)+ # Share-safe cross-device setup report (read-only) — names why THIS+ # install behaves differently from another device (CLAUDE.md §3 triage).+ app.include_router(setup_report_router)# Frontier auto-switch modal API (GET pending / POST ack) + Self-Mod# read/restore API. Both were the last route modules left unmounted; the# 404 on /api/frontier/pending silently broke the desktop auto-switchdiff --git a/jarvis/ui/web/setup_report_routes.py b/jarvis/ui/web/setup_report_routes.pynew file mode 100644index 0000000000..e99d64f1a9--- /dev/null+++ b/jarvis/ui/web/setup_report_routes.py@@ -0,0 +1,242 @@+"""Cross-device setup report — makes "why is THIS install different?" a 2-minute read.++The most expensive cross-device misdiagnosis (CLAUDE.md §3, device-parity+triage ritual): a feature "missing" on a second machine is usually not a code+bug but an invisible setup difference — a key that exists only on the dev box,+a tier that quietly crossed to a fallback family, a wake word never set.+This route aggregates the signals that already exist elsewhere (active tier+resolution, credential presence, section health) into ONE snapshot per device,+so two installs can be compared side by side and every difference has a name.++Share-safe by construction: the report carries key PRESENCE (booleans) only,+never key values, and no personal filesystem paths or machine names — it may+be pasted into an issue or chat without scrubbing.++* ``GET /api/setup-report`` — structured JSON+* ``GET /api/setup-report?format=text`` — human-readable plain text++Read-only and imported lazily by ``server.py`` (AP-26: nothing here runs at+boot). The section-health part reuses ``provider_routes``' cached snapshot and+is bounded by a timeout, so a cold cache degrades the report honestly+(``sections_complete: false``) instead of hanging the caller.+"""++from __future__ import annotations++import asyncio+import logging+import platform as platform_mod+import sys+import time+from typing import Any++from fastapi import APIRouter, Query, Request+from fastapi.responses import PlainTextResponse++from . import provider_routes as _providers+from . import update_routes as _update++log = logging.getLogger(__name__)++router = APIRouter(prefix="/api/setup-report", tags=["setup-report"])++# Ceiling for the section-health portion. On a warm cache this is instant; on+# a cold one the shared snapshot task keeps computing after we stop waiting+# (``section_health`` shields it), so a retry a few seconds later completes.+_SECTION_TIMEOUT_S = 20.0+++# --------------------------------------------------------------------------- #+# Snapshot builders (each fail-soft: a probe error degrades, never 500s)+# --------------------------------------------------------------------------- #+def _version() -> str:+ try:+ import jarvis++ return str(jarvis.__version__)+ except (ImportError, AttributeError):+ return "unknown"+++def _platform_snapshot() -> dict[str, Any]:+ """OS/runtime facts. Deliberately no hostname — the report stays share-safe."""+ return {+ "os": sys.platform,+ "os_release": f"{platform_mod.system()} {platform_mod.release()}",+ "python": platform_mod.python_version(),+ "machine": platform_mod.machine(),+ }+++def _install_snapshot() -> dict[str, Any]:+ """Managed-install marker + profile — is this a user install or a dev tree?"""+ try:+ root = _update._repo_root()+ managed = bool(root is not None and (root / _update._MARKER_NAME).exists())+ profile = _update._managed_install_profile(root) if root is not None else "unknown"+ except Exception: # noqa: BLE001 — diagnostics must never raise+ managed, profile = False, "unknown"+ return {"managed": managed, "profile": profile}+++def _behavior_snapshot(request: Request) -> dict[str, Any]:+ """Config facts that change day-to-day behavior between two devices.++ Presence booleans over raw values wherever the value is personal (the wake+ phrase names the user's assistant brand).+ """+ cfg = _providers._resolve_cfg(request)+ trigger = getattr(cfg, "trigger", None)+ wake = getattr(trigger, "wake_word", None)+ brain = getattr(cfg, "brain", None)+ phrase = str(getattr(wake, "phrase", "") or "")+ return {+ "wake_word_enabled": bool(getattr(trigger, "wake_word_enabled", False)),+ "wake_phrase_set": bool(phrase.strip()),+ "wake_engine": str(getattr(wake, "engine", "") or "unknown"),+ "reply_language": str(getattr(brain, "reply_language", "") or "auto"),+ }+++def _active_tiers(request: Request) -> dict[str, str | None]:+ """The provider ACTUALLY powering each tier (post-fallback), per device."""+ return {+ "brain": _providers._active_brain(request),+ "stt": _providers._active_stt(request),+ "tts": _providers._active_tts(request),+ "realtime": _providers._active_realtime(request),+ "computer_use": _providers._active_computer_use(request),+ }+++def _credential_presence(request: Request) -> dict[str, bool]:+ """Key PRESENCE per provider — strictly booleans, never a value.++ Reads every secret slot (keyring/ENV/.env), which is synchronous and slow;+ the route runs this off the event loop.+ """+ binary_path = _providers._codex_binary_path(request)+ out: dict[str, bool] = {}+ for spec in _providers.PROVIDERS:+ try:+ present = bool(+ _providers._is_credential_present(spec, binary_path if spec.id == "codex" else None)+ )+ except Exception: # noqa: BLE001 — an unreadable slot reads as absent+ present = False+ out[spec.id] = present+ return out+++async def _section_snapshot(request: Request) -> dict[str, dict[str, str]] | None:+ """Per-tier health, reason-coded — reuses the section-health cache.++ ``None`` means the probe did not complete in time (cold cache); the report+ says so honestly instead of blocking or guessing.+ """+ try:+ resp = await asyncio.wait_for(+ _providers.section_health(request, refresh=False),+ timeout=_SECTION_TIMEOUT_S,+ )+ except TimeoutError:+ return None+ except Exception as exc: # noqa: BLE001 — diagnostics must never raise+ log.debug("setup-report: section health unavailable: %s", exc)+ return None+ return {+ name: {"status": s.status, "reason": s.reason, "detail": s.detail}+ for name, s in resp.sections.items()+ }+++def _degradations(sections: dict[str, dict[str, str]] | None) -> list[str]:+ """Every tier that is NOT silently fine, with its machine-readable reason.++ This list is the whole point of the report: quiet capability degradation+ (AP-22 fallback chains) is what makes a second device "mysteriously"+ different, and here it gets named.+ """+ out: list[str] = []+ for name, section in sorted((sections or {}).items()):+ if section.get("status") in ("ok", "unknown"):+ continue+ detail = section.get("detail") or ""+ out.append(f"{name}: {section.get('reason', 'unknown')} ({detail})".strip())+ return out+++def _summary(report: dict[str, Any]) -> list[str]:+ """Stable, ordered one-liners — diff two devices' summaries line by line."""+ plat = report["platform"]+ install = report["install"]+ behavior = report["behavior"]+ lines = [+ f"version: {report['version']}",+ f"platform: {plat['os_release']} | python {plat['python']} | {plat['machine']}",+ f"install: {'managed' if install['managed'] else 'dev/manual'} ({install['profile']})",+ f"wake: {'on' if behavior['wake_word_enabled'] else 'off'}"+ f" | phrase {'set' if behavior['wake_phrase_set'] else 'NOT set'}"+ f" | engine {behavior['wake_engine']}",+ f"reply language: {behavior['reply_language']}",+ ]+ for tier in sorted(report["tiers"]):+ lines.append(f"tier {tier}: {report['tiers'][tier] or '-'}")+ keyed = sorted(pid for pid, ok in report["credentials"].items() if ok)+ lines.append("keys present: " + (", ".join(keyed) if keyed else "none"))+ if not report["sections_complete"]:+ lines.append("health: probe still warming up - re-request in a few seconds")+ for entry in report["degradations"]:+ lines.append("degraded " + entry)+ return lines+++def _render_text(report: dict[str, Any]) -> str:+ header = "Personal Jarvis setup report (share-safe: key presence only, never values)"+ body = "\n".join(report["summary"])+ return f"{header}\n{'=' * len(header)}\n{body}\n"+++# --------------------------------------------------------------------------- #+# Route+# --------------------------------------------------------------------------- #+async def get_setup_report(+ request: Request,+ fmt: str = Query(default="json", alias="format"),+) -> Any:+ """One share-safe snapshot of what powers THIS install, for device diffing."""++ def _sync_parts() -> tuple[dict[str, Any], dict[str, str | None], dict[str, bool]]:+ # Config reads, plugin-registry resolution, and keyring probes are all+ # synchronous — off the loop so the report never stalls the server.+ return (+ _behavior_snapshot(request),+ _active_tiers(request),+ _credential_presence(request),+ )++ behavior, tiers, credentials = await asyncio.to_thread(_sync_parts)+ sections = await _section_snapshot(request)++ report: dict[str, Any] = {+ "schema": 1,+ "generated_at": time.strftime("%Y-%m-%dT%H:%M:%S%z"),+ "version": _version(),+ "platform": _platform_snapshot(),+ "install": _install_snapshot(),+ "behavior": behavior,+ "tiers": tiers,+ "credentials": credentials,+ "sections": sections or {},+ "sections_complete": sections is not None,+ "degradations": _degradations(sections),+ }+ report["summary"] = _summary(report)++ if fmt == "text":+ return PlainTextResponse(_render_text(report))+ return report+++__all__ = ["router"]diff --git a/tests/unit/ui/web/test_setup_report_routes.py b/tests/unit/ui/web/test_setup_report_routes.pynew file mode 100644index 0000000000..69372c5d28--- /dev/null+++ b/tests/unit/ui/web/test_setup_report_routes.py@@ -0,0 +1,123 @@+"""REST-route tests for the cross-device setup report.++The report exists to name why one install behaves differently from another+(CLAUDE.md §3 device-parity triage), so the tests pin its three contracts:++1. Share-safety: credentials appear strictly as presence BOOLEANS — a report+ must be pasteable into an issue without scrubbing.+2. Degradation naming: every non-ok section surfaces in ``degradations`` and+ in the diffable ``summary`` lines; silently-fine sections do not.+3. Honesty under a cold cache: a section probe that does not complete in time+ yields ``sections_complete: false`` and still answers 200 — never a hang,+ never a guess.++The probe helpers are monkeypatched: the real ones read the OS keyring and the+live config, which a unit test must not touch (fakes over mocks per repo+convention — these are plain stub functions).+"""++from __future__ import annotations++from typing import Any++from fastapi import FastAPI+from fastapi.testclient import TestClient++from jarvis.ui.web import setup_report_routes as sr+++def _stub_probes(+ monkeypatch: Any,+ *,+ sections: dict[str, dict[str, str]] | None,+) -> None:+ monkeypatch.setattr(+ sr,+ "_behavior_snapshot",+ lambda request: {+ "wake_word_enabled": True,+ "wake_phrase_set": True,+ "wake_engine": "vosk_kws",+ "reply_language": "auto",+ },+ )+ monkeypatch.setattr(+ sr,+ "_active_tiers",+ lambda request: {+ "brain": "gemini",+ "stt": "faster-whisper",+ "tts": "elevenlabs",+ "realtime": None,+ "computer_use": "gemini",+ },+ )+ monkeypatch.setattr(+ sr,+ "_credential_presence",+ lambda request: {"gemini": True, "openai": False, "elevenlabs": True},+ )+ monkeypatch.setattr(+ sr,+ "_install_snapshot",+ lambda: {"managed": True, "profile": "full"},+ )++ async def _sections(request: Any) -> dict[str, dict[str, str]] | None:+ return sections++ monkeypatch.setattr(sr, "_section_snapshot", _sections)+++def _client() -> TestClient:+ app = FastAPI()+ app.include_router(sr.router)+ return TestClient(app)+++_SECTIONS = {+ "brain": {"status": "ok", "reason": "ok", "detail": "Gemini: ok"},+ "tts": {+ "status": "needs_setup",+ "reason": "not_configured",+ "detail": "Gemini Flash TTS: no key set",+ },+}+++def test_report_names_degradations_and_keeps_credentials_boolean(monkeypatch):+ _stub_probes(monkeypatch, sections=_SECTIONS)+ body = _client().get("/api/setup-report").json()++ assert body["version"]+ assert body["sections_complete"] is True+ # Contract 1 — share-safe: presence booleans only, never a value.+ assert body["credentials"] and all(isinstance(v, bool) for v in body["credentials"].values())+ # Contract 2 — the quiet degradation gets named; the healthy tier stays out.+ assert body["degradations"] == ["tts: not_configured (Gemini Flash TTS: no key set)"]+ assert any(line.startswith("degraded tts:") for line in body["summary"])+ assert not any("brain: ok" in line and "degraded" in line for line in body["summary"])+ # Summary lines are the device-diff surface: active tiers + key inventory.+ assert "tier brain: gemini" in body["summary"]+ assert "keys present: elevenlabs, gemini" in body["summary"]+++def test_text_format_renders_the_summary_lines(monkeypatch):+ _stub_probes(monkeypatch, sections=_SECTIONS)+ resp = _client().get("/api/setup-report", params={"format": "text"})++ assert resp.status_code == 200+ assert resp.headers["content-type"].startswith("text/plain")+ assert "keys present: elevenlabs, gemini" in resp.text+ assert "share-safe" in resp.text+++def test_cold_section_probe_degrades_honestly(monkeypatch):+ # Contract 3 — a timed-out health probe must not hang, 500, or fabricate.+ _stub_probes(monkeypatch, sections=None)+ body = _client().get("/api/setup-report").json()++ assert body["sections_complete"] is False+ assert body["sections"] == {}+ assert body["degradations"] == []+ assert any("warming up" in line for line in body["summary"])