Files
nixos-core/AGENTS.md
T
kiskaadee 1f99dbed41 docs(core): rewrite AGENTS.md and README.md for self-contained governance
- Condense AGENTS.md around context discovery hierarchy, core/sites
  invariants, anti-tautology TDD rules, verification gates (./scripts/test
  and pyright), internal MADR rules, and git commit hygiene.
- Redesign README.md into a 5-section instance-agnostic entrypoint covering
  system topology, repository layout, operator quickstart, and docs index.
- Move the Current Baseline vs. Target Architecture matrix to ROADMAP.md
  and replace remaining personal domain references with RFC placeholders.
2026-10-15 18:44:34 -05:00

80 lines
5.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Homelab Core — Agent Guidelines
This repository defines the declarative NixOS host foundation, shared infrastructure services, security boundaries, and the `appctl` operational control plane. Independent application workloads live in `~/Sites` and integrate through declarative `app.yaml` manifests and Docker Compose definitions.
---
## 1. Context Discovery & Hierarchy of Truth
Before proposing or implementing changes, establish context in this order:
1. **Architectural Decisions (`docs/decisions/`)**: Check [`docs/decisions/README.md`](docs/decisions/README.md) and local ADRs for binding design commitments.
2. **Architecture & Contracts (`docs/`)**: Consult [`docs/architecture.md`](docs/architecture.md), [`docs/appctl.md`](docs/appctl.md), [`docs/gitops.md`](docs/gitops.md), and [`docs/secrets-and-state.md`](docs/secrets-and-state.md) for current runtime behavior.
3. **Trajectory & Active Work (`ROADMAP.md`, `todo.txt`, `git log`)**: Verify milestone scope, active tasks, and recent commit history before modifying adjacent subsystems.
When a requested change conflicts with an architectural invariant or accepted ADR, **stop and surface the conflict** before implementing a workaround.
---
## 2. Architectural Invariants
1. **Core / Sites Boundary**:
- **Core owns**: NixOS host configuration, shared platform services (ingress, SSO/LDAP, mail, monitoring), security policy, and deployment mechanics.
- **`~/Sites` owns**: Application workloads, workload-specific `docker-compose.yml`, and workload intent (`app.yaml`).
- Never hardcode workload-specific domains, ports, containers, or policies in Core (`scripts/appctl*`, GitOps), and never move Core platform services into `~/Sites`.
2. **Declarative Workload Manifests (`app.yaml`)**:
- Workloads are self-describing via strict, fail-closed Pydantic v2 schemas (`scripts/core_manifest.py`).
- Never introduce arbitrary command execution, host filesystem paths, privileged flags, or Docker control capabilities into `app.yaml`.
3. **GitOps Trust Boundary**:
- Webhook admission requires cryptographic authentication (HMAC-SHA256).
- Repository identity and filesystem paths are resolved strictly through trusted Core logic (`config/deployments.yaml`)—never directly from webhook payloads.
- Execution must remain allowlisted, serialized (`flock`), and free of shell interpolation (`shell=False`).
4. **Docker & Privilege Isolation**:
- `socket-proxy` is the **only** container permitted to mount `/var/run/docker.sock` (strictly `:ro`, read-only API capabilities only).
- Never add `privileged: true`, host namespace sharing, or direct Docker socket mounts to workload or control-plane containers.
5. **Secrets & Runtime State**:
- Never commit plaintext secrets, keys, hashes, certificates, or runtime databases.
- Host secrets are managed via SOPS (`sops-nix`) and projected to `/run/secrets/`. Persistent mutable state lives outside Git in dedicated state directories or Docker volumes.
6. **Platform Genericism & License**:
- Keep all code, templates, tests, and documentation strictly instance-agnostic. Inject domains and identities at runtime (`HOMELAB_DOMAIN`, `DOMAIN_SUFFIX`).
- Use RFC 2606 placeholders (`example.com`, `example.org`, `example.test`) in tests and documentation—never personal domains or operator usernames.
- Preserve [The Unlicense](UNLICENSE) across the repository.
---
## 3. Engineering Practices & TDD
- **TDD-First**: Write or update failing unit, structural, or security tests in `tests/` before or alongside implementation changes.
- **No Tautological Tests**: Every test must import and execute real production code or scripts and assert on observable outcomes. Never write tests that only inspect local mock strings, hardcode expected results into the fixture under test, or pass when the production invariant is broken.
- **Fail-Closed Contracts**: Validate external inputs (YAML manifests, webhook payloads, CLI arguments, subprocess outputs) through strict schemas and explicit error paths. Never swallow diagnostic `stderr` silently.
---
## 4. Step Closure & Verification Gate
Every implementation step must close with automated verification before proposing a commit:
```bash
./scripts/test # Ruff linter + Pytest suite + nix flake check + NixOS drv eval
nix develop --command pyright # Static type analysis across Python scripts and tests
```
Run context-specific validation when modifying container or service definitions:
```bash
docker compose config -q
```
Do not bypass failing tests by weakening or removing an invariant test unless the architecture itself has intentionally changed via an approved decision.
---
## 5. Internal Documentation & Git Hygiene
- **Repository Documentation (`docs/`)**: Keep documentation concise, accurate to current code reality, and formatted in GitHub-Flavored Markdown compatible with Obsidian.
- **Architecture Decision Records (`docs/decisions/`)**: Record binding repository-level architectural decisions in MADR 4.0 format (`NNNN-slug.md`) and register them in [`docs/decisions/README.md`](docs/decisions/README.md).
- **Task Tracking (`todo.txt`)**: Maintain a comment-free root `todo.txt` formatted for `tuxedo` / `todo.sh` (`(A)`–`(C)` priorities, `+<project>`, `@<context>`). Mark verified deliverables completed (`x YYYY-MM-DD ...`) immediately.
- **Git & Commits**:
- Never commit directly to `main`/`master`.
- Never run destructive Git commands (`reset --hard`, `restore`, `clean -fd`, `push --force`) without explicit user confirmation.
- Stage atomic changes and use Conventional Commits (`feat`, `fix`, `refactor`, `test`, `docs`, `chore`), waiting for user approval before committing.