Skip to content

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.

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.md
index 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.md
index 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 system
diff --git a/.claude/skills/security-audit/references/threat-model.md b/.claude/skills/security-audit/references/threat-model.md
index 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 pred
diff --git a/ODSTUPANJA.md b/ODSTUPANJA.md
index 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.md
index 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 itself
anything, so the name is reduced to printable characters and 64 characters; the collector reads the
file 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-pr
and 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 no
network 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 it
before 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.Dockerfile
index ae1264c..f8f3ef6 100644
--- a/docker/collector.Dockerfile
+++ b/docker/collector.Dockerfile
@@ -2,7 +2,7 @@
FROM python:3.12-alpine
WORKDIR /app
-COPY src/agent/collector.py ./collector.py
+COPY src/collector/collector.py ./collector.py
ENV INFRADECK_STATE_DIR=/var/lib/infradeck-collector \
HOST_PROC=/host/proc \
diff --git a/docker/docker-proxy.Dockerfile b/docker/docker-proxy.Dockerfile
index 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-alpine
WORKDIR /app
-COPY src/agent/docker_proxy.py ./docker_proxy.py
+COPY src/collector/docker_proxy.py ./docker_proxy.py
ENV 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.Dockerfile
index 17e45a5..6cce2e3 100644
--- a/docker/system-helper.Dockerfile
+++ b/docker/system-helper.Dockerfile
@@ -3,7 +3,7 @@
FROM python:3.12-alpine
WORKDIR /app
-COPY src/agent/system_helper.py ./system_helper.py
+COPY src/collector/system_helper.py ./system_helper.py
ENV HOST_PROC=/proc \
INFRADECK_WTMP_PATH=/host/wtmp \
diff --git a/docs/development.md b/docs/development.md
index 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 key
reset_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 helper
frontend/ React + Tailwind dashboard (Vite); charts.jsx and chartMath.js are the
charts (distributions.jsx: columns, donut, bars, heatmap), StatisticsPage.jsx,
FleetStatistics.jsx, ServerInsights.jsx and ContainerStatistics.jsx the page
diff --git a/src/agent/__init__.py b/src/agent/__init__.py
new file mode 100644
index 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.py
similarity index 100%
rename from src/agent/service.py
rename to src/agent/chat.py
diff --git a/src/backend/agent_jobs.py b/src/agent/jobs.py
similarity index 100%
rename from src/backend/agent_jobs.py
rename to src/agent/jobs.py
diff --git a/src/backend/agent_usage.py b/src/agent/usage.py
similarity index 99%
rename from src/backend/agent_usage.py
rename to src/agent/usage.py
index 14f757d..1c8cc0f 100644
--- a/src/backend/agent_usage.py
+++ b/src/agent/usage.py
@@ -12,7 +12,7 @@ from datetime import datetime, timedelta, timezone
from sqlalchemy import func
-from .models import AgentRun, AppSetting
+from ..backend.models import AgentRun, AppSetting
PRICES_KEY = "agent_prices"
CAP_KEY = "agent_monthly_cap_usd"
diff --git a/src/agent/worker.py b/src/agent/worker.py
index 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 means
incidents wait for their diagnosis; everything else keeps working. Run with ``python -m src.agent.worker``;
@@ -15,7 +15,7 @@ import sys
import threading
import time
-from src.backend import agent_jobs, agent_usage
+from src.agent import jobs, usage
from src.backend.config import REDIS_URL
from src.backend.db import SessionLocal
from 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 1
stopping = 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.py
index 7609f24..9070184 100644
--- a/src/backend/alerts.py
+++ b/src/backend/alerts.py
@@ -9,7 +9,7 @@ from __future__ import annotations
from collections.abc import Iterable
from datetime import datetime, timezone
-from . import agent_jobs
+from ..agent import jobs as agent_jobs
from .models import IncidentAlert
INFO, WARNING, CRITICAL = "INFO", "WARNING", "CRITICAL"
diff --git a/src/backend/main.py b/src/backend/main.py
index ed492a9..b6b74ad 100644
--- a/src/backend/main.py
+++ b/src/backend/main.py
@@ -27,7 +27,7 @@ from sqlalchemy import case, func, inspect, text
from .alerts import CONTAINER_RULE_PREFIX, CRITICAL, SERVER_OFFLINE_RULE, SEVERITIES, active_rule_keys, raise_alert, resolve_alerts, sync_alerts
import 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, totp
from .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_firewall
from .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_usage
from ..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_message
class 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__.py
new file mode 100644
index 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.py
similarity index 99%
rename from src/agent/collector.py
rename to src/collector/collector.py
index 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, and
INFRADECK_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 (standard
library only; it ships as a container image). Docker access is optional; when
the socket is unavailable, host metrics continue to be sent.
"""
diff --git a/src/agent/docker_proxy.py b/src/collector/docker_proxy.py
similarity index 98%
rename from src/agent/docker_proxy.py
rename to src/collector/docker_proxy.py
index 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) live
leave this process. Paths are matched literally, with no decoding or normalisation, so there is
nothing 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 annotations
diff --git a/src/agent/system_helper.py b/src/collector/system_helper.py
similarity index 99%
rename from src/agent/system_helper.py
rename to src/collector/system_helper.py
index 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 grants
it, 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 annotations
diff --git a/tests/assistant/test_agent_service.py b/tests/assistant/test_agent_service.py
index a98c6b6..313c174 100644
--- a/tests/assistant/test_agent_service.py
+++ b/tests/assistant/test_agent_service.py
@@ -2,7 +2,7 @@ import threading
import pytest
-from src.agent.service import AgentService
+from src.agent.chat import AgentService
class 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_service
from src.agent.providers import Completion, OpenAIProvider
diff --git a/tests/assistant/test_agent_worker.py b/tests/assistant/test_agent_worker.py
index 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 sessionmaker
from sqlalchemy.pool import StaticPool
from src.agent import worker
-from src.backend import agent_jobs, alerts
+from src.agent import jobs as agent_jobs
+from src.backend import alerts
from src.backend.models import Base, IncidentAlert, Server
from tests.fakes import FakeRedis
diff --git a/tests/collectors/test_collector_mounts.py b/tests/collectors/test_collector_mounts.py
index 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 collector
MOUNTS = """\
/dev/sda1 / ext4 rw 0 0
diff --git a/tests/collectors/test_dashboard_host.py b/tests/collectors/test_dashboard_host.py
index 9c12eda..e4109e5 100644
--- a/tests/collectors/test_dashboard_host.py
+++ b/tests/collectors/test_dashboard_host.py
@@ -9,7 +9,7 @@ from fastapi import HTTPException
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
-from src.agent import collector
+from src.collector import collector
from src.backend import main
from src.backend.models import Base, HostMetric, Server, User
diff --git a/tests/collectors/test_docker_proxy.py b/tests/collectors/test_docker_proxy.py
index 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 BaseHTTPRequestHandler
import pytest
-from src.agent import collector, docker_proxy as proxy
+from src.collector import collector, docker_proxy as proxy
CID = "a" * 64
SECRET = "SUPER_SECRET_TOKEN_123"
diff --git a/tests/collectors/test_enrollment.py b/tests/collectors/test_enrollment.py
index 9bb675a..f04352e 100644
--- a/tests/collectors/test_enrollment.py
+++ b/tests/collectors/test_enrollment.py
@@ -9,7 +9,7 @@ from fastapi import HTTPException
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
-from src.agent import collector
+from src.collector import collector
from src.backend import main
from 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 collector
legacy = 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.py
index 0ea370d..aca0067 100644
--- a/tests/collectors/test_pending_collectors.py
+++ b/tests/collectors/test_pending_collectors.py
@@ -10,7 +10,7 @@ from fastapi import HTTPException
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
-from src.agent import collector
+from src.collector import collector
from src.backend import main
from src.backend.models import Base, JoinToken, PendingCollector, Server, User
diff --git a/tests/history/test_container_stats.py b/tests/history/test_container_stats.py
index 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_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import StaticPool
-from src.agent import collector
+from src.collector import collector
from src.backend import history, main, rollups, stats
from src.backend.models import Base, ContainerMetric, HostMetric, Server, User
from tests.fakes import FakeRedis
diff --git a/tests/monitoring/test_container_checks.py b/tests/monitoring/test_container_checks.py
index a1d05ca..79eff03 100644
--- a/tests/monitoring/test_container_checks.py
+++ b/tests/monitoring/test_container_checks.py
@@ -10,7 +10,7 @@ import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
-from src.agent import collector
+from src.collector import collector
from src.backend import alerts, main, rules
from src.backend.models import Base, ContainerMetric, HostMetric, IncidentAlert, Server, SystemEvent, User
diff --git a/tests/monitoring/test_container_detail.py b/tests/monitoring/test_container_detail.py
index c509046..9148e2a 100644
--- a/tests/monitoring/test_container_detail.py
+++ b/tests/monitoring/test_container_detail.py
@@ -9,7 +9,7 @@ from fastapi import HTTPException
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
-from src.agent import collector
+from src.collector import collector
from src.backend import main
from src.backend.models import Base, ContainerMetric, Server, User
diff --git a/tests/monitoring/test_dashboard_data.py b/tests/monitoring/test_dashboard_data.py
index 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_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import StaticPool
-from src.agent import collector, system_helper
+from src.collector import collector, system_helper
from src.backend import dashboard, main
from src.backend.models import Base, ContainerMetric, HostMetric, IncidentAlert, PendingCollector, Server, SystemEvent, User
from tests.fakes import FakeRedis
diff --git a/tests/monitoring/test_network_checks.py b/tests/monitoring/test_network_checks.py
index 39763e3..1af2687 100644
--- a/tests/monitoring/test_network_checks.py
+++ b/tests/monitoring/test_network_checks.py
@@ -11,7 +11,7 @@ import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
-from src.agent import collector
+from src.collector import collector
from src.backend import alerts, main, rules
from src.backend.models import Base, FirewallState, HostMetric, IncidentAlert, ListenerState, Server, SystemEvent, User
diff --git a/tests/monitoring/test_system_checks.py b/tests/monitoring/test_system_checks.py
index 325d8a9..645780c 100644
--- a/tests/monitoring/test_system_checks.py
+++ b/tests/monitoring/test_system_checks.py
@@ -8,7 +8,7 @@ import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
-from src.agent import collector
+from src.collector import collector
from src.backend import main
from src.backend.models import Base, IncidentAlert, Server, SystemEvent, User
diff --git a/tests/monitoring/test_system_helper.py b/tests/monitoring/test_system_helper.py
index 2f1dc26..8ce2281 100644
--- a/tests/monitoring/test_system_helper.py
+++ b/tests/monitoring/test_system_helper.py
@@ -11,7 +11,7 @@ import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
-from src.agent import collector, system_helper as helper
+from src.collector import collector, system_helper as helper
from src.backend import main
from src.backend.models import Base, IncidentAlert, Server, SystemEvent, User
diff --git a/tests/security/test_second_review.py b/tests/security/test_second_review.py
index 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 service
instance = object.__new__(service.AgentService) if hasattr(service, "AgentService") else None
if 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 collector
path = tmp_path / "state" / "credentials.json"
collector.save_credentials(7, "secret-token", path)