An AI SRE for your homelab that has to show its work.
NEXUS investigates incidents the way a careful human operator would: it observes the real infrastructure, collects evidence with typed tools, forms hypotheses, tests them, and only then explains a root cause. Risky actions need human approval. Every conclusion must be backed by something it actually observed.
Core principle: NEXUS must never confuse sounding confident with being correct.
When it can't prove something, the correct answer is:
"I could not verify disk usage because the host did not respond."
...not "Disk usage is normal."
Most "AI ops" demos ask an LLM to guess. NEXUS is built around the opposite constraint. It embodies four hard rules:
| Rule | What it means in practice |
|---|---|
| Evidence over vibes | Confidence is derived from observations, contradictions, and required-evidence coverage — never invented by the model. |
| Allowlist, not denylist | No arbitrary bash -c, sudo, or rm -rf. Every capability is a typed tool with a permission class. |
| Approval before risk | REQUIRES_APPROVAL actions cannot run until a human says yes. The authorization layer lives outside the LLM. |
| Explainable, not opaque | The console shows reasoning summaries and evidence — never hidden chain-of-thought. |
This is the difference between a system that can restart a container and a system that can show you why it was safe to restart, what evidence supported it, and proof the service recovered.
You: "Immich is down."
NEXUS: classify → SERVICE_UNAVAILABLE
context → Immich, its host, PostgreSQL + Redis deps,
recent changes, recent related incidents
evidence → container status, recent logs, dependency health,
host disk/memory
hypothesis → "Immich's container is in a crash loop caused by
PostgreSQL refusing connections after disk filled."
test → check disk usage + Postgres logs on the same host
root cause → storage exhaustion on the host filesystem
remediation → prune stale Docker build cache (LOW_RISK)
safety → disk change → REQUIRES_APPROVAL
approve → you click Approve
execute → run allowlisted action
verify → Immich healthcheck passes, logs stop repeating
close → full trace + outcome recorded for evaluation
The reasoning graph loops whenever evidence is insufficient — it does not invent a root cause just to finish.
NEXUS is built in verifiable phases. Nothing below is claimed until it is tested and running.
Real, working, and verified against live PostgreSQL and Redis:
- FastAPI application factory +
/api/v1/healthwith a real database check - PostgreSQL 16 persistence — full domain schema (hosts, services, dependencies, incidents, evidence, agent runs, tool calls, approvals, audit logs, evaluations) via SQLAlchemy 2.0 async
- Alembic migrations (async) applied to a live database
- Redis 7 via Docker Compose
- Structured logging (
structlog), typed config (pydantic-settings) - CLI entrypoint (
nexus), sandbox compose stack for safe testing - CI: ruff, mypy (
strict), pytest against real PG + Redis services - Graceful degradation: the app boots and reports
degradedwhen the DB is down
Real, read-only observation of the local host, with honest failure:
- Typed tool layer (
nexus/tools/) — every capability declares a permission class - Allowlist permission policy (
READ_ONLY/LOW_RISK/REQUIRES_APPROVAL/FORBIDDEN), enforced outside the LLM; a new policy denies everything FORBIDDENis evaluated first, so no mode or approval can reach it- Read-only host probes: disk usage, memory, OS, load average, CPU count
Evidencerecords carry an explicitOBSERVED/UNAVAILABLEstatus, so "I could not verify disk usage because the host did not respond" is a result the system can actually produce- Inventory endpoints:
GET /api/v1/inventory/host,GET /api/v1/tools,POST /api/v1/tools/{tool_name} - Approvals must be issued, never asserted — an HTTP caller cannot approve its own action (see ADR-0003)
Changing something, without making "safe" something a caller has to remember:
- Every mutating capability is split into two tools —
docker.plan_prune_cache(READ_ONLY) anddocker.prune_cache(REQUIRES_APPROVAL), anddocker.plan_restart_container(READ_ONLY) withdocker.restart_container(LOW_RISK). Those two pairs are the only mutating actions that exist. There is nodry_runflag whose default could be forgotten in a prompt, a retry, or a loop; a mutation is simply a different name with a different permission class - The plan twin's name is derived from the action's name, and the test suite asserts every mutating action has one, so the pair cannot drift apart
- Plans are evidence, not predictions — the plan tool runs the real read-only command and the approval request carries that output
- Propose → approve → execute → verify as separate steps
(
nexus/services/remediation.py) - One approval buys one action, atomically. The grant is claimed in a
single method with no
awaitinside it — asyncio yields only at anawait, so a method that cannot yield cannot interleave, and the read-check-write cannot race. Two concurrent requests sharing oneapproval_idproduce one200and one403, and the command vector appears exactly once. The trade is honest and worth stating: claiming burns the grant. It is spent whether the action succeeded, failed or was cancelled, because a command that was started cannot be un-started — so a crash between the claim and the command means the operator has to approve again, which is the correct direction to fail - A refusal that never needed the grant does not spend one.
executedecides first with no grant at all, soREAD_ONLY_MODE,UNKNOWN_TOOLandFORBIDDENrefusals return without claiming anything - Mutating tools are unreachable from
POST /api/v1/tools/{tool_name}. That route refusesLOW_RISKandREQUIRES_APPROVALnames with403andMUTATING_TOOL_REQUIRES_REMEDIATION_ROUTE, before the approval store is consulted — so a grant cannot be spent on an action that was never proposed, even inPERMISSIVEmode and even with a genuine grant in the body.FORBIDDENnames are deliberately not diverted: they must reach the policy to be reported asFORBIDDEN_TOOL, which is ADR-0002's precedence holding - Verification is a separate read after the fact. A zero exit code is evidence a
command ran, not that a service recovered — and if the re-read is impossible the
result is
UNAVAILABLE, never an inferred success - A zero exit code is not a state change. A prune reporting
Total reclaimed space: 0BisUNCHANGEDwithchanged is False, notCHANGED. An authorized call that produced no outcome (unusable arguments) is400, not a200with a null body - No arbitrary shell. Every action is a fixed argument vector. No template, no free text, no shell; the one caller-supplied token is a container name, validated against a narrow pattern and passed as a separate argv element
- Disabled by default (
NEXUS_REMEDIATION_ENABLED=false), which means the mutating tools are absent from the allowlist (UNKNOWN_TOOL) rather than locked - Endpoints:
GET /api/v1/remediations,POST /api/v1/remediations/{action}/proposal,POST /api/v1/remediations/{action},POST /api/v1/remediations/{action}/verification - Still no route can issue an approval — that asymmetry is ADR-0003 working as intended
- Tested against real subprocesses, not just mocks:
subprocess_runneris exercised withsys.executable(neverdocker, so no daemon is required), covering shell-metacharacter passthrough, exit codes, a missing binary and a timeout. No test in this repository has actually rundocker builder prune, because the tests deliberately do not need Docker to mean anything
- Phase 3 — Safe remediation actions behind the approval gate
- Phase 4 — LangGraph agent (investigate → evidence → diagnose → explain)
- Phase 5 — Dynamic context engine
- Phase 6 — Evaluation framework (25+ scenarios, regression gates)
- Phase 7 — Observability (Langfuse tracing)
- Phase 8 — Operator-facing approval flow + audit UI
- Phase 9 — Chaos lab (controlled failure scenarios)
- Phase 10 — Operations console (React/Next.js)
- Phase 11 — Hardening, API authentication, regression testing
Honest rule of this repo: features are marked
REAL,SIMULATED,MOCK, orNOT IMPLEMENTED. See docs/architecture.md.
┌─────────────────────┐
│ Web Console │
│ React/Next.js │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ FastAPI │
│ API │
└──────────┬──────────┘
┌───────────────┼────────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Agent Engine │ │ Infrastructure│ │ Evaluation │
│ LangGraph │ │ Service │ │ Service │
└──────┬───────┘ └──────────────┘ └──────────────┘
│
▼
┌──────────────────┐
│ Context Engine │
└────────┬─────────┘
│
┌────────┼─────────┐
▼ ▼ ▼
Tools State Knowledge
│ │ │
▼ ▼ ▼
Docker PostgreSQL Topology
Linux Redis Graph
Network
Storage
Metrics
Logs
│
▼
Actual Homelab
Clean boundaries between API, agent orchestration, context engineering, tools,
infrastructure state, evaluation, observability, and frontend. No monolith
"main.py" — see src/nexus/.
Requirements: Python 3.12+, Docker / Docker Compose.
git clone https://github.com/mfalme0/nexus.git
cd nexus
# 1. Start PostgreSQL + Redis
docker compose up -d
# 2. Install (editable, with dev tools)
python -m venv .venv
# Windows: .venv\Scripts\activate
source .venv/bin/activate
pip install -e ".[dev]"
# 3. Apply the schema
alembic upgrade head
# 4. Run the API
uvicorn nexus.main:app --reload --port 8000Then open http://localhost:8000/docs for the interactive OpenAPI docs, or:
curl http://localhost:8000/api/v1/health
# {"status":"healthy","version":"0.1.0","checks":{"database":"healthy"}}make test # pytest
make lint # ruff
make typecheck # mypy --strictmake dev, make migrate, and make sandbox-up are also available.
The evaluation harness is a Phase 6 deliverable, so there is deliberately no eval
target (#1 removed one that pointed at a module that never existed). An eval
command that ran and reported nothing would be worse than no command at all.
The homelab holds real services and real data, so safety is a hard requirement, not a feature flag.
- Default mode is
READ_ONLY. It is the default in code, not a convention, and the policy refuses anything that is notREAD_ONLYunder it. - Mutating tools are absent by default.
NEXUS_REMEDIATION_ENABLED=falsemeansdocker.prune_cacheis not in the allowlist at all — refused asUNKNOWN_TOOL. Registration is what denies, so a forgotten switch is the safe outcome rather than the dangerous one. - Tool permission classes:
READ_ONLY,LOW_RISK,REQUIRES_APPROVAL,FORBIDDEN. The model cannot bypass them; authorization is enforced outside the LLM. Two independent switches (NEXUS_REMEDIATION_ENABLEDandNEXUS_REMEDIATION_EXECUTION_MODE) stand between a default deployment and a mutation, andREQUIRES_APPROVALadds a third: an issued, single-use grant. - One route to a mutation, and the grant is claimed atomically.
POST /api/v1/tools/{tool_name}is for observation and refuses mutating names outright;POST /api/v1/remediations/{action}is the only route that can perform one. There, the grant is taken in a single non-yielding method, so concurrent requests sharing oneapproval_idcannot both clear the gate. Claiming spends it — see the Phase 3 section for why that is the correct direction to fail. - Settings in
.envare read by every group, and a typo is silent. Each settings class declares its ownenv_file. That was a bug fix, not a feature: writingNEXUS_REMEDIATION_ENABLED=trueto.envused to raiseValidationErrorat import, because pydantic-settings does not propagate a parent's dotenv source into a nested settings model. The fix requiredextra="ignore"on the root model, which means a misspelledNEXUS_*variable is now ignored rather than reported. Treat the documented names as a contract. - Early testing runs against a dedicated Docker Compose sandbox, never the production homelab by default. The sandbox is a convenience, not a security boundary.
- Secrets stay in environment variables, are never logged, and are never committed.
- What is not defended yet — no API authentication, no transport security, no
sandbox for the remediation commands, which shell out to the
dockerCLI and inherit its authority, and no validation that aNEXUS_*variable you meant to set was spelled correctly. See SECURITY.md.
src/nexus/
├── api/ # FastAPI routes (thin): health, inventory, tools, remediations
├── agent/ # LangGraph orchestration — NOT IMPLEMENTED (Phase 4)
├── tools/ # typed tool layer, permission policy, host probes, remediation
├── security/ # issued approvals and pending approval requests
├── services/ # host discovery + the propose/execute/verify remediation flow
├── db/ # SQLAlchemy models, engine, sessions (schema only — no CRUD)
├── config.py # pydantic-settings configuration
├── logging.py # structlog configuration
└── main.py # application factory
alembic/ # database migrations
tests/ # unit + integration tests
docs/ # architecture and decision records
- Architecture
- ADR-0001: Phase 1 foundation
- ADR-0002: Tool permissions are an allowlist decided outside the model
- ADR-0003: Approvals must be issued, not asserted
- ADR-0004: Plan and mutation are two tool names, not one argument
- Contributing — including the honesty rules this repo follows
- Security policy — threat model, and what is not defended yet
More land as each phase completes: agent design, context engineering, tool security, evaluation, observability, failure analysis, and chaos engineering.
Issues and pull requests are welcome — see CONTRIBUTING.md. Security vulnerabilities should go through private advisory reporting, not a public issue: see SECURITY.md.
NEXUS is not optimized to look impressive. It is optimized to be correct, observable, testable, explainable, recoverable, and safe.
The impressive part is not that an LLM can restart Docker. It is that NEXUS can say: here is what I observed, here is what I believe happened, here is the evidence, here is what I'm uncertain about, here is the safest available action, here is why I'm allowed to take it, and here is proof the system recovered.
MIT