Self-hosted monitoring for homelabs: host and container metrics and uptime checks from all your machines in one dashboard, with an optional AI agent that diagnoses incidents and suggests fixes.
Python ai-agentsaiopsdashboarddockerfastapihomelabincident-managementllmmonitoringopenaireactroot-cause-analysisself-hosteduptime-monitoring
refactor: src/agent holds only the incident agent; collector parts in src/collector
karloks20055a1fe10435af
diff --git a/.claude/skills/security-audit/SKILL.md b/.claude/skills/security-audit/SKILL.mdindex 889946f..e55f199 100644--- a/.claude/skills/security-audit/SKILL.md+++ b/.claude/skills/security-audit/SKILL.md@@ -22,10 +22,10 @@ tek kad korisnik to izričito zatraži.|---|---|| `full` | sve dolje, redom || `backend` | `src/backend/**` |-| `collector` | `src/agent/**` (collector, docker_proxy, system_helper, assistant, health_checks) |+| `collector` | `src/collector/**` (collector, docker_proxy, system_helper) || `infra` | `docker/**`, `*compose*.yml`, `example.env`, `.github/**`, `.gitignore`, `.dockerignore` || `frontend` | `src/frontend/**` |-| `assistant` | LLM asistent: `src/agent/{service,prompts,health_checks}.py`, `SYSTEM_PROMPT.md`, konverzacije u backendu |+| `assistant` | Incident agent: `src/agent/**` (providers, chat, prompts, health_checks, jobs, worker, usage), `SYSTEM_PROMPT.md`, konverzacije u backendu || `<path>` | taj put (datoteka ili direktorij) plus ono što ga poziva || `diff` | samo neprihvaćene promjene (`git diff` + `git diff --staged`) pročitane u kontekstu cijelih datoteka |diff --git a/.claude/skills/security-audit/references/checklist-collector-agent.md b/.claude/skills/security-audit/references/checklist-collector-agent.mdindex 7e49cc7..89089d7 100644--- a/.claude/skills/security-audit/references/checklist-collector-agent.md+++ b/.claude/skills/security-audit/references/checklist-collector-agent.md@@ -1,4 +1,4 @@-# Kontrolna lista: collector, docker proxy, system helper, LLM asistent (`src/agent/**`)+# Kontrolna lista: collector, docker proxy, system helper (`src/collector/**`), incident agent (`src/agent/**`)Čitaj `collector.py`, `docker_proxy.py`, `system_helper.py`, `health_checks.py`, `service.py`,`prompts.py`, `main.py`, `utils.py` i `SYSTEM_PROMPT.md` u cijelosti. Docker proxy i systemdiff --git a/.claude/skills/security-audit/references/threat-model.md b/.claude/skills/security-audit/references/threat-model.mdindex 36bf70b..785ab11 100644--- a/.claude/skills/security-audit/references/threat-model.md+++ b/.claude/skills/security-audit/references/threat-model.md@@ -11,10 +11,10 @@ razilaze, **vjeruj kodu** i to prijavi kao nalaz o dokumentaciji.| Backend (FastAPI) | `src/backend` | Postgres, interni mrežni segment | obrađuje sve ulaze || Postgres | `docker/postgres/init` | samo backend | sadrži hashove, šifrirane TOTP tajne, podatke o hostovima || Collector gate | `docker/nginx.collector.conf` | backend; jedan port na VPN adresi | jedini put do collector endpointa |-| Collector | `src/agent/collector.py` | `/proc` hosta, host FS read-only (`/hostfs`), Docker proxy, backend preko HTTP-a | pokreće se na udaljenim hostovima, može biti kompromitiran |-| Docker proxy | `src/agent/docker_proxy.py` | Docker socket (uid 0), Unix socket prema collectoru | drži root-ekvivalentan pristup; mora ostati minimalan |-| System helper (opcionalno) | `src/agent/system_helper.py` | kernel log, wtmp, `CAP_SYSLOG` | privilegiran; njegov izlaz je nepouzdan |-| LLM asistent | `src/agent/service.py`, `prompts.py`, `SYSTEM_PROMPT.md`, `health_checks.py` | fiksni read-only provjere, opcionalni webhook | ulaz uključuje podatke s hosta |+| Collector | `src/collector/collector.py` | `/proc` hosta, host FS read-only (`/hostfs`), Docker proxy, backend preko HTTP-a | pokreće se na udaljenim hostovima, može biti kompromitiran |+| Docker proxy | `src/collector/docker_proxy.py` | Docker socket (uid 0), Unix socket prema collectoru | drži root-ekvivalentan pristup; mora ostati minimalan |+| System helper (opcionalno) | `src/collector/system_helper.py` | kernel log, wtmp, `CAP_SYSLOG` | privilegiran; njegov izlaz je nepouzdan |+| LLM asistent | `src/agent/chat.py`, `prompts.py`, `SYSTEM_PROMPT.md`, `health_checks.py` | fiksni read-only provjere, opcionalni webhook | ulaz uključuje podatke s hosta || CI | `.github/workflows/images.yml` | GHCR, cosign | opskrbni lanac za slike koje hostovi izvršavaju |Izvan repozitorija (nisu u opsegu, ali ih treba imati na umu kao pretpostavke): Traefik preddiff --git a/ODSTUPANJA.md b/ODSTUPANJA.mdindex 1a2dd26..e7d8c72 100644--- a/ODSTUPANJA.md+++ b/ODSTUPANJA.md@@ -14,7 +14,7 @@ su anotacije dizajna i namjerno nisu ugrađeni.| --- | --- | --- | --- || „karlo's homelab" kao ime instance | Zadano se izvodi iz imena prvog admina; mijenja se u Admin → General | – | – || „Owner" ispod imena korisnika | „Owner" se prikazuje svakom adminu, „Member" svima ostalima | Ne postoji uloga vlasnika | #106 |-| Verzija `v0.9.2` | Konstanta u `src/backend/config.py` i druga u `src/agent/collector.py` | Nema jednog izvora verzije pri buildu | #106 |+| Verzija `v0.9.2` | Konstanta u `src/backend/config.py` i druga u `src/collector/collector.py` | Nema jednog izvora verzije pri buildu | #106 || Prečac `⌘K` | Na Linuxu i Windowsu piše `Ctrl K` | Prikazuje se prečac koji stvarno radi na tom sustavu | – |## Overview (`01-dashboard.pdf`, `06-dashboard-empty-states.pdf`)diff --git a/SECURITY.md b/SECURITY.mdindex 236705e..a45fb62 100644--- a/SECURITY.md+++ b/SECURITY.md@@ -92,7 +92,7 @@ What it can and cannot do:(not logins, users or addresses).- **Reads, never writes, the kernel log:** it uses the non-destructive read-all call.- **No code is fetched from the dashboard.** The helper is built from this repository. Review- `src/agent/system_helper.py` (about 200 lines, standard library only) before enabling it.+ `src/collector/system_helper.py` (about 200 lines, standard library only) before enabling it.How its output is treated as untrusted:@@ -125,7 +125,7 @@ Be clear about what you are granting:- **What leaves it:** protocol, port and process name, at most 512 entries. A process can name itselfanything, so the name is reduced to printable characters and 64 characters; the collector reads thefile with `O_NOFOLLOW`, a size cap and a freshness check, and the backend validates it again.-- It is the same single file as the system helper (`src/agent/system_helper.py`), in a different mode.+- It is the same single file as the system helper (`src/collector/system_helper.py`), in a different mode.## The Docker socket and the read-only proxy@@ -154,7 +154,7 @@ compose files the collector **does not mount the socket**. A separate `docker-prand images already are. If a path itself is sensitive, don't put it in a container's mounts.- It runs with all capabilities dropped, a read-only filesystem and `no-new-privileges`, with nonetwork at all. It listens on a Unix socket (mode 0660) in a volume that only the collector shares.-- It is one standard-library file, `src/agent/docker_proxy.py`, built from this repository. Review it+- It is one standard-library file, `src/collector/docker_proxy.py`, built from this repository. Review itbefore trusting it: it is the one piece that holds the socket.A compromised collector can therefore read what it already reports (container names, states,diff --git a/docker/collector.Dockerfile b/docker/collector.Dockerfileindex ae1264c..f8f3ef6 100644--- a/docker/collector.Dockerfile+++ b/docker/collector.Dockerfile@@ -2,7 +2,7 @@FROM python:3.12-alpineWORKDIR /app-COPY src/agent/collector.py ./collector.py+COPY src/collector/collector.py ./collector.pyENV INFRADECK_STATE_DIR=/var/lib/infradeck-collector \HOST_PROC=/host/proc \diff --git a/docker/docker-proxy.Dockerfile b/docker/docker-proxy.Dockerfileindex 9bf4699..cb5f418 100644--- a/docker/docker-proxy.Dockerfile+++ b/docker/docker-proxy.Dockerfile@@ -1,9 +1,9 @@# Read-only Docker API proxy: the only container that mounts the Docker socket.-# Standard library only. See src/agent/docker_proxy.py for exactly what it allows.+# Standard library only. See src/collector/docker_proxy.py for exactly what it allows.FROM python:3.12-alpineWORKDIR /app-COPY src/agent/docker_proxy.py ./docker_proxy.py+COPY src/collector/docker_proxy.py ./docker_proxy.pyENV DOCKER_SOCKET_PATH=/var/run/docker.sock \INFRADECK_DOCKER_PROXY_SOCKET=/run/docker-proxy/docker.sock \diff --git a/docker/system-helper.Dockerfile b/docker/system-helper.Dockerfileindex 17e45a5..6cce2e3 100644--- a/docker/system-helper.Dockerfile+++ b/docker/system-helper.Dockerfile@@ -3,7 +3,7 @@FROM python:3.12-alpineWORKDIR /app-COPY src/agent/system_helper.py ./system_helper.py+COPY src/collector/system_helper.py ./system_helper.pyENV HOST_PROC=/proc \INFRADECK_WTMP_PATH=/host/wtmp \diff --git a/docs/development.md b/docs/development.mdindex cfbce47..d1a2762 100644--- a/docs/development.md+++ b/docs/development.md@@ -84,12 +84,17 @@ src/totp.py one-time codes and recovery codes (standard library only)secrets_box.py encrypts stored secrets with SECRETS_KEY; also prints a new keyreset_2fa.py command-line two-factor reset for a locked-out account- agent/- collector.py metrics collector (standard library only)- docker_proxy.py read-only Docker API proxy (standard library only)- system_helper.py optional kernel-log / wtmp helper (standard library only)- health_checks.py read-only checks available to the assistant- service.py, prompts.py, providers.py incident agent chat (OpenAI)+ agent/ the incident agent; runs in the backend (chat) and the agent-worker container+ providers.py the language model behind one interface (OpenAI)+ chat.py, prompts.py, SYSTEM_PROMPT.md the incident chat and its instructions+ health_checks.py the fixed, read-only checks the agent may ask for+ jobs.py job queue in Redis: published after an incident opens or worsens+ worker.py the agent-worker container: runs the queued jobs+ usage.py tokens, cost per model, monthly budget, daily chat limit+ collector/ runs on every monitored machine, each file its own small image (standard library only)+ collector.py metrics collector+ docker_proxy.py read-only Docker API proxy+ system_helper.py optional kernel-log / wtmp / port-owners helperfrontend/ React + Tailwind dashboard (Vite); charts.jsx and chartMath.js are thecharts (distributions.jsx: columns, donut, bars, heatmap), StatisticsPage.jsx,FleetStatistics.jsx, ServerInsights.jsx and ContainerStatistics.jsx the pagediff --git a/src/agent/__init__.py b/src/agent/__init__.pynew file mode 100644index 0000000..c5a47d3--- /dev/null+++ b/src/agent/__init__.py@@ -0,0 +1,2 @@+"""The incident agent: the language model behind it (providers), the chat, its fixed read-only checks, the job queue+it works through, what it costs, and the worker that runs its jobs."""diff --git a/src/agent/service.py b/src/agent/chat.pysimilarity index 100%rename from src/agent/service.pyrename to src/agent/chat.pydiff --git a/src/backend/agent_jobs.py b/src/agent/jobs.pysimilarity index 100%rename from src/backend/agent_jobs.pyrename to src/agent/jobs.pydiff --git a/src/backend/agent_usage.py b/src/agent/usage.pysimilarity index 99%rename from src/backend/agent_usage.pyrename to src/agent/usage.pyindex 14f757d..1c8cc0f 100644--- a/src/backend/agent_usage.py+++ b/src/agent/usage.py@@ -12,7 +12,7 @@ from datetime import datetime, timedelta, timezonefrom sqlalchemy import func-from .models import AgentRun, AppSetting+from ..backend.models import AgentRun, AppSettingPRICES_KEY = "agent_prices"CAP_KEY = "agent_monthly_cap_usd"diff --git a/src/agent/worker.py b/src/agent/worker.pyindex 4274585..c38dee5 100644--- a/src/agent/worker.py+++ b/src/agent/worker.py@@ -1,4 +1,4 @@-"""The agent worker: takes jobs from the queue in Redis (see src/backend/agent_jobs.py) and runs them one at a time.+"""The agent worker: takes jobs from the queue in Redis (see src/agent/jobs.py) and runs them one at a time.It runs in its own container, so a slow or stuck model never holds up the backend, and stopping it only meansincidents wait for their diagnosis; everything else keeps working. Run with ``python -m src.agent.worker``;@@ -15,7 +15,7 @@ import sysimport threadingimport time-from src.backend import agent_jobs, agent_usage+from src.agent import jobs, usagefrom src.backend.config import REDIS_URLfrom src.backend.db import SessionLocalfrom src.backend.models import IncidentAlert@@ -33,14 +33,14 @@ def handle_incident(job: dict) -> tuple[str, str]:return "skipped", "The incident no longer exists."if incident.status != "active":return "skipped", "The incident was already resolved."- if agent_usage.budget(db)["state"] == "paused":+ if usage.budget(db)["state"] == "paused":return "skipped", "This month's budget for the agent is used up."return "noted", "Automatic diagnosis is not built yet (#116); the incident keeps its rule-based diagnosis."finally:db.close()-HANDLERS = {agent_jobs.OPENED: handle_incident, agent_jobs.WORSENED: handle_incident}+HANDLERS = {jobs.OPENED: handle_incident, jobs.WORSENED: handle_incident}def run_with_timeout(handler, job: dict, seconds: float) -> tuple[str, str]:@@ -74,13 +74,13 @@ def process(redis_client, raw: str, handlers=None, timeout: float = JOB_TIMEOUT_job = json.loads(raw)handler = handlers[job["type"]]except (ValueError, KeyError, TypeError):- agent_jobs.finish(redis_client, raw, {"type": "unknown"}, "failed", "Not a job this worker knows.")+ jobs.finish(redis_client, raw, {"type": "unknown"}, "failed", "Not a job this worker knows.")return "failed"try:status_text, note_text = run_with_timeout(handler, job, timeout)except Exception as exc:- return agent_jobs.retry_or_fail(redis_client, raw, job, f"{type(exc).__name__}: {exc}", round((time.monotonic() - started) * 1000))- agent_jobs.finish(redis_client, raw, job, status_text, note_text, round((time.monotonic() - started) * 1000))+ return jobs.retry_or_fail(redis_client, raw, job, f"{type(exc).__name__}: {exc}", round((time.monotonic() - started) * 1000))+ jobs.finish(redis_client, raw, job, status_text, note_text, round((time.monotonic() - started) * 1000))return status_text@@ -90,19 +90,19 @@ def main() -> int:# Waiting for a job blocks for POLL_SECONDS, so reads must be allowed to take longer than that.client = redis.Redis.from_url(REDIS_URL, decode_responses=True, socket_timeout=POLL_SECONDS + 10, socket_connect_timeout=5)if "--health" in sys.argv:- return 0 if client.get(agent_jobs.HEARTBEAT) else 1+ return 0 if client.get(jobs.HEARTBEAT) else 1stopping = threading.Event()for name in (signal.SIGTERM, signal.SIGINT):signal.signal(name, lambda *_: stopping.set())- started_at = agent_jobs.now_iso()- recovered = agent_jobs.recover(client)+ started_at = jobs.now_iso()+ recovered = jobs.recover(client)print(f"Agent worker started{f'; {recovered} unfinished jobs back in the queue' if recovered else ''}.", flush=True)while not stopping.is_set():try:- agent_jobs.beat(client, started_at)- agent_jobs.promote_due(client)- raw = agent_jobs.take(client, POLL_SECONDS)+ jobs.beat(client, started_at)+ jobs.promote_due(client)+ raw = jobs.take(client, POLL_SECONDS)if raw is not None:outcome = process(client, raw)print(f"Agent job {outcome}: {raw[:200]}", flush=True)diff --git a/src/backend/alerts.py b/src/backend/alerts.pyindex 7609f24..9070184 100644--- a/src/backend/alerts.py+++ b/src/backend/alerts.py@@ -9,7 +9,7 @@ from __future__ import annotationsfrom collections.abc import Iterablefrom datetime import datetime, timezone-from . import agent_jobs+from ..agent import jobs as agent_jobsfrom .models import IncidentAlertINFO, WARNING, CRITICAL = "INFO", "WARNING", "CRITICAL"diff --git a/src/backend/main.py b/src/backend/main.pyindex ed492a9..b6b74ad 100644--- a/src/backend/main.py+++ b/src/backend/main.py@@ -27,7 +27,7 @@ from sqlalchemy import case, func, inspect, textfrom .alerts import CONTAINER_RULE_PREFIX, CRITICAL, SERVER_OFFLINE_RULE, SEVERITIES, active_rule_keys, raise_alert, resolve_alerts, sync_alertsimport contextvars-from . import agent_jobs, agent_usage, auth, dashboard, history as history_service, incidents, notify, rollups, secrets_box, stats, totp+from . import auth, dashboard, history as history_service, incidents, notify, rollups, secrets_box, stats, totpfrom .auth import (STAGE_ENROLLMENT, STAGE_FULL, count_pending_attempt, create_pending_two_factor, create_session, delete_pending_two_factor, delete_session, get_recent_logs,get_session, get_user_from_session, hash_password, issue_recovery_codes, list_user_sessions, pending_two_factor_remember, read_pending_two_factor, session_lifetime, recovery_codes_left, record_audit_log,@@ -64,8 +64,9 @@ from .config import ()from .rules import HELPER_EVENT_KINDS, DEFAULT_THRESHOLDS, HOST_RULE_PREFIX, container_rules, host_rules, validate_thresholds, detect_system_events, system_rules, SYSTEM_RULE_PREFIX, validate_mount_thresholds, validate_helper_events, REBOOT_DETAILS, REBOOT_KEY_PREFIX, detect_container_events, memory_trend_rules, CONTAINER_EVENT_KINDS, MAX_CONTAINER_EVENTS_PER_CHECKIN, MAX_CONTAINER_EVENTS_PER_HOUR, TREND_RULE_PREFIX, NETWORK_EVENT_KINDS, NETWORK_RULE_PREFIX, MAX_NETWORK_EVENTS_PER_CHECKIN, MAX_NETWORK_EVENTS_PER_HOUR, INTERNET_STATUSES, LISTENER_SCOPES, LISTENER_PROTOCOLS, MAX_LISTENERS, FIREWALL_LABELS, detect_listener_changes, detect_firewall_changes, network_rules, validate_listeners, validate_firewallfrom .rate_limit import enforce_ip_limit, enforce_limit, enforce_login_limit, enforce_register_limit, refund_attempt, reset_limits+from ..agent import jobs as agent_jobs, usage as agent_usagefrom ..agent.providers import configured_key-from ..agent.service import check_provider_connection, delete_agent_conversation, send_agent_message+from ..agent.chat import check_provider_connection, delete_agent_conversation, send_agent_messageclass RegisterRequest(BaseModel):@@ -231,7 +232,7 @@ def agent_error_message(exc: Exception) -> str:redis_client = redis.Redis.from_url(REDIS_URL, decode_responses=True)-# Jobs for the agent worker are published after the commit that opened or escalated an incident (see agent_jobs).+# Jobs for the agent worker are published after the commit that opened or escalated an incident (see src/agent/jobs.py).agent_jobs.redis_getter = lambda: redis_client# The interactive API documentation is a map of every endpoint, so it is off unless ENABLE_API_DOCS=true.app = FastAPI(title="Infradeck API", docs_url="/docs" if ENABLE_API_DOCS else None, redoc_url=None, openapi_url="/openapi.json" if ENABLE_API_DOCS else None)diff --git a/src/collector/__init__.py b/src/collector/__init__.pynew file mode 100644index 0000000..5bdb21e--- /dev/null+++ b/src/collector/__init__.py@@ -0,0 +1,4 @@+"""What runs on every monitored machine: the collector, the read-only Docker proxy and the optional system helper.++Each is one standard-library file, built into its own small image (see docker/*.Dockerfile), so none of them+imports anything from the backend or from each other."""diff --git a/src/agent/collector.py b/src/collector/collector.pysimilarity index 99%rename from src/agent/collector.pyrename to src/collector/collector.pyindex 49481ed..28e4bba 100644--- a/src/agent/collector.py+++ b/src/collector/collector.py@@ -6,7 +6,7 @@ it receives its token (no restart) and saves it under INFRADECK_STATE_DIR.INFRADECK_JOIN_TOKEN (from the dashboard's Connect a server command) proves who asked it to join.INFRADECK_ENROLL_KEY skips the approval step for automated installs, andINFRADECK_SERVER_ID / INFRADECK_COLLECTOR_TOKEN still work as explicit credentials.-Run with ``python -m src.agent.collector`` or as a standalone script (standard+Run with ``python -m src.collector.collector`` or as a standalone script (standardlibrary only; it ships as a container image). Docker access is optional; whenthe socket is unavailable, host metrics continue to be sent."""diff --git a/src/agent/docker_proxy.py b/src/collector/docker_proxy.pysimilarity index 98%rename from src/agent/docker_proxy.pyrename to src/collector/docker_proxy.pyindex fbd8901..96b552a 100644--- a/src/agent/docker_proxy.py+++ b/src/collector/docker_proxy.py@@ -18,7 +18,7 @@ inspect output is where a container's environment variables (often secrets) liveleave this process. Paths are matched literally, with no decoding or normalisation, so there isnothing for traversal or encoding tricks to work on.-Standard library only. Run with ``python -m src.agent.docker_proxy`` or as a standalone script.+Standard library only. Run with ``python -m src.collector.docker_proxy`` or as a standalone script."""from __future__ import annotationsdiff --git a/src/agent/system_helper.py b/src/collector/system_helper.pysimilarity index 99%rename from src/agent/system_helper.pyrename to src/collector/system_helper.pyindex 4f4b5c1..b88f501 100644--- a/src/agent/system_helper.py+++ b/src/collector/system_helper.py@@ -16,7 +16,7 @@ right to look at other users' processes (CAP_SYS_PTRACE and CAP_DAC_READ_SEARCH)any file on the host. It therefore runs as its own container, so enabling the kernel-log helper never grantsit, and it publishes nothing but protocol, port and process name.-Standard library only. Run with ``python -m src.agent.system_helper`` or as a standalone script.+Standard library only. Run with ``python -m src.collector.system_helper`` or as a standalone script."""from __future__ import annotationsdiff --git a/tests/assistant/test_agent_service.py b/tests/assistant/test_agent_service.pyindex a98c6b6..313c174 100644--- a/tests/assistant/test_agent_service.py+++ b/tests/assistant/test_agent_service.py@@ -2,7 +2,7 @@ import threadingimport pytest-from src.agent.service import AgentService+from src.agent.chat import AgentServiceclass FakeResponse:@@ -66,7 +66,7 @@ def test_arbitrary_command_is_rejected_before_execution():from types import SimpleNamespace-from src.agent import service as agent_service+from src.agent import chat as agent_servicefrom src.agent.providers import Completion, OpenAIProviderdiff --git a/tests/assistant/test_agent_worker.py b/tests/assistant/test_agent_worker.pyindex ecbaa62..2238494 100644--- a/tests/assistant/test_agent_worker.py+++ b/tests/assistant/test_agent_worker.py@@ -9,7 +9,8 @@ from sqlalchemy.orm import sessionmakerfrom sqlalchemy.pool import StaticPoolfrom src.agent import worker-from src.backend import agent_jobs, alerts+from src.agent import jobs as agent_jobs+from src.backend import alertsfrom src.backend.models import Base, IncidentAlert, Serverfrom tests.fakes import FakeRedisdiff --git a/tests/collectors/test_collector_mounts.py b/tests/collectors/test_collector_mounts.pyindex e288ca0..7d0bce9 100644--- a/tests/collectors/test_collector_mounts.py+++ b/tests/collectors/test_collector_mounts.py@@ -1,6 +1,6 @@import os-from src.agent import collector+from src.collector import collectorMOUNTS = """\/dev/sda1 / ext4 rw 0 0diff --git a/tests/collectors/test_dashboard_host.py b/tests/collectors/test_dashboard_host.pyindex 9c12eda..e4109e5 100644--- a/tests/collectors/test_dashboard_host.py+++ b/tests/collectors/test_dashboard_host.py@@ -9,7 +9,7 @@ from fastapi import HTTPExceptionfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker-from src.agent import collector+from src.collector import collectorfrom src.backend import mainfrom src.backend.models import Base, HostMetric, Server, Userdiff --git a/tests/collectors/test_docker_proxy.py b/tests/collectors/test_docker_proxy.pyindex 3f486d9..99d5f57 100644--- a/tests/collectors/test_docker_proxy.py+++ b/tests/collectors/test_docker_proxy.py@@ -6,7 +6,7 @@ from http.server import BaseHTTPRequestHandlerimport pytest-from src.agent import collector, docker_proxy as proxy+from src.collector import collector, docker_proxy as proxyCID = "a" * 64SECRET = "SUPER_SECRET_TOKEN_123"diff --git a/tests/collectors/test_enrollment.py b/tests/collectors/test_enrollment.pyindex 9bb675a..f04352e 100644--- a/tests/collectors/test_enrollment.py+++ b/tests/collectors/test_enrollment.py@@ -9,7 +9,7 @@ from fastapi import HTTPExceptionfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker-from src.agent import collector+from src.collector import collectorfrom src.backend import mainfrom src.backend.models import Base, EnrollmentKey, IncidentAlert, Server, User@@ -135,7 +135,7 @@ def test_machine_id_read_from_host_root(tmp_path, monkeypatch):def test_a_collector_from_before_the_rename_keeps_its_credentials_and_settings(tmp_path, monkeypatch):- from src.agent import collector+ from src.collector import collectorlegacy = tmp_path / "homelab-collector"legacy.mkdir()(legacy / "credentials.json").write_text('{"server_id": 4, "token": "t"}')diff --git a/tests/collectors/test_pending_collectors.py b/tests/collectors/test_pending_collectors.pyindex 0ea370d..aca0067 100644--- a/tests/collectors/test_pending_collectors.py+++ b/tests/collectors/test_pending_collectors.py@@ -10,7 +10,7 @@ from fastapi import HTTPExceptionfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker-from src.agent import collector+from src.collector import collectorfrom src.backend import mainfrom src.backend.models import Base, JoinToken, PendingCollector, Server, Userdiff --git a/tests/history/test_container_stats.py b/tests/history/test_container_stats.pyindex 097963f..5396aa6 100644--- a/tests/history/test_container_stats.py+++ b/tests/history/test_container_stats.py@@ -11,7 +11,7 @@ from sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmakerfrom sqlalchemy.pool import StaticPool-from src.agent import collector+from src.collector import collectorfrom src.backend import history, main, rollups, statsfrom src.backend.models import Base, ContainerMetric, HostMetric, Server, Userfrom tests.fakes import FakeRedisdiff --git a/tests/monitoring/test_container_checks.py b/tests/monitoring/test_container_checks.pyindex a1d05ca..79eff03 100644--- a/tests/monitoring/test_container_checks.py+++ b/tests/monitoring/test_container_checks.py@@ -10,7 +10,7 @@ import pytestfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker-from src.agent import collector+from src.collector import collectorfrom src.backend import alerts, main, rulesfrom src.backend.models import Base, ContainerMetric, HostMetric, IncidentAlert, Server, SystemEvent, Userdiff --git a/tests/monitoring/test_container_detail.py b/tests/monitoring/test_container_detail.pyindex c509046..9148e2a 100644--- a/tests/monitoring/test_container_detail.py+++ b/tests/monitoring/test_container_detail.py@@ -9,7 +9,7 @@ from fastapi import HTTPExceptionfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker-from src.agent import collector+from src.collector import collectorfrom src.backend import mainfrom src.backend.models import Base, ContainerMetric, Server, Userdiff --git a/tests/monitoring/test_dashboard_data.py b/tests/monitoring/test_dashboard_data.pyindex ca91d63..c3c7de5 100644--- a/tests/monitoring/test_dashboard_data.py+++ b/tests/monitoring/test_dashboard_data.py@@ -13,7 +13,7 @@ from sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmakerfrom sqlalchemy.pool import StaticPool-from src.agent import collector, system_helper+from src.collector import collector, system_helperfrom src.backend import dashboard, mainfrom src.backend.models import Base, ContainerMetric, HostMetric, IncidentAlert, PendingCollector, Server, SystemEvent, Userfrom tests.fakes import FakeRedisdiff --git a/tests/monitoring/test_network_checks.py b/tests/monitoring/test_network_checks.pyindex 39763e3..1af2687 100644--- a/tests/monitoring/test_network_checks.py+++ b/tests/monitoring/test_network_checks.py@@ -11,7 +11,7 @@ import pytestfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker-from src.agent import collector+from src.collector import collectorfrom src.backend import alerts, main, rulesfrom src.backend.models import Base, FirewallState, HostMetric, IncidentAlert, ListenerState, Server, SystemEvent, Userdiff --git a/tests/monitoring/test_system_checks.py b/tests/monitoring/test_system_checks.pyindex 325d8a9..645780c 100644--- a/tests/monitoring/test_system_checks.py+++ b/tests/monitoring/test_system_checks.py@@ -8,7 +8,7 @@ import pytestfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker-from src.agent import collector+from src.collector import collectorfrom src.backend import mainfrom src.backend.models import Base, IncidentAlert, Server, SystemEvent, Userdiff --git a/tests/monitoring/test_system_helper.py b/tests/monitoring/test_system_helper.pyindex 2f1dc26..8ce2281 100644--- a/tests/monitoring/test_system_helper.py+++ b/tests/monitoring/test_system_helper.py@@ -11,7 +11,7 @@ import pytestfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker-from src.agent import collector, system_helper as helper+from src.collector import collector, system_helper as helperfrom src.backend import mainfrom src.backend.models import Base, IncidentAlert, Server, SystemEvent, Userdiff --git a/tests/security/test_second_review.py b/tests/security/test_second_review.pyindex 57f794d..4043c73 100644--- a/tests/security/test_second_review.py+++ b/tests/security/test_second_review.py@@ -295,7 +295,7 @@ def test_server_ids_in_the_address_must_fit_too(app, path):# --- the smaller points from the review ------------------------------------------------------------------------------------------def test_the_assistants_memory_of_chats_is_bounded_and_forgets_the_least_recently_used(monkeypatch):- from src.agent import service+ from src.agent import chat as serviceinstance = object.__new__(service.AgentService) if hasattr(service, "AgentService") else Noneif instance is None:@@ -327,7 +327,7 @@ def test_a_limited_session_expires_sooner_than_a_full_one(app):def test_collector_credentials_are_created_private_from_the_start(tmp_path):- from src.agent import collector+ from src.collector import collectorpath = tmp_path / "state" / "credentials.json"collector.save_credentials(7, "secret-token", path)