my-homelab-configs/docs/ai-ops.md

241 lines
8.7 KiB
Markdown

# Jeannie AI & Operations
## Implementation Language Policy
Jeannie keeps `./jeannie` as the stable command entrypoint. New durable
read-only orchestration, report rendering, inventory parsing, status/doctor
logic, and self-heal planning should prefer Go under `cmd/jeannie-core` because
it ships as one small binary and is easier to test than Bash. Bash remains for
thin compatibility wrappers and remote shell glue. Python remains acceptable for
AI/RAG, data-heavy utilities, or cases where an existing Python ecosystem is the
clear fit. New repo features should choose the smallest language that fits the
task instead of defaulting to Bash.
## Debian-Hosted AI Stack
The current AI stack is part of the Debian operations layer, not the Kubernetes
workload layer. That is deliberate: if the Pimox workers or Kubernetes control
plane are unhealthy, the triage tools still need to be available from the host
that runs Jeannie.
The split is:
- OmniRoute runs in Docker Compose under `/data/homelab-ai-stack` and exposes an
OpenAI-compatible endpoint on the Debian host.
- `deploy-ai-stack` seeds local OpenRouter and NVIDIA keys when present,
creates the no-auth/free provider connections, validates real chat
completions, rejects stale routes, and writes
`/data/homelab-ai-stack/models.env`.
- `deploy-ai-tools` keeps `goose`, `holmes`, and `hermes` as bare-metal tools
and generates wrapper commands (`jeannie-goose`, `jeannie-holmes`,
`jeannie-hermes`) plus `/data/homelab-ai-stack/ai-tools.env`.
- `ai-check` verifies the knowledge index, wrappers, OmniRoute endpoint, and
validated model route hints before Jeannie relies on them.
- Ollama remains on Debian for single-purpose local tasks such as translation
cache misses, but Holmes agentic Kubernetes triage should use the
OmniRoute-backed routes.
Bootstrap and validation from the Debian server:
```bash
./jeannie deploy-ai-stack
./jeannie deploy-ai-tools
./jeannie ai-check
```
## Holmes-Assisted Kubernetes Doctor
`doctor-k8s` is the first integration point between deterministic Jeannie
doctors and the AI stack. It collects read-only Kubernetes evidence, writes an
artifact directory under `~/.local/share/homelab/doctor-k8s`, and asks Holmes
for triage through the OmniRoute route selected in `models.env`.
```bash
./jeannie doctor-k8s
./jeannie doctor-k8s --no-holmes
```
The evidence bundle identifies the selected profile, runtime, and control-plane
node. Failed reads are marked unknown. Holmes must return JSON with cited check
IDs; Jeannie renders facts from the evidence and validates citations and any
next command using the same rules as compact status explanations. An invalid
response is rejected and the deterministic artifacts remain available. The
private artifact directory holds the evidence, validated explanation, raw model
response, and error log. Schema validation cannot prove a hypothesis correct.
Holmes is instructed not to call tools and is invoked with `--bash-always-deny`;
this is not a substitute for restricting its credentials and configured tools.
The selected OmniRoute provider can be local or external. Remediation remains
outside this diagnostic flow and goes through Jeannie's guarded actions.
## Hermes and Jeannie
`./jeannie hermes-connect` installs and enables the `jeannie-readonly` Hermes
plugin, then restarts the user gateway. `deploy-hermes` also runs this step.
The plugin exposes `jeannie_status` (fast JSON health report) and
`jeannie_runbooks` (cited local index lookup). It follows the saved Jeannie
profile for each call and rejects status data if the profile or pinned UID
changes. The response hook prefixes the selected profile and runtime, or reports
that profile lookup failed. It describes the saved selection, not proof that
the cluster is running.
The integration provides no mutation or arbitrary-command tool. It does not
disable other Hermes tools or change their permissions. The output hook depends
on the installed Hermes version and other active response-transform plugins;
verify the header in both CLI and Matrix after deployment. The checkout that
ran `hermes-connect` is recorded as the plugin's Jeannie source. Runbook lookup
requires an existing `./jeannie ai-index`. OmniRoute may use an external model
provider, depending on the configured route.
## AI Evals
The repo includes a local eval harness for Jeannie explanations and homelab RAG
grounding. It uses fixtures and allowlisted read-only commands, so it is safe to
run before changing the lab:
```bash
./jeannie ai-evals run
```
Use `./jeannie ai-evals list` to see the current cases. Add new cases
under `infra/ai-evals` whenever a troubleshooting pattern or runbook behavior
should become repeatable.
## Prompt Injection Lab
The defensive security training path includes local prompt-injection fixtures
for hostile runbooks, tool output, dashboard annotations, and command arguments.
Run it without touching live infrastructure:
```bash
./jeannie prompt-injection-lab run
```
Cases live under `security/prompt-injection-lab` and are meant to become
regression tests for future Jeannie AI features.
## Incident Commander
The repo also includes a read-only incident commander trainer. It classifies
pasted failure text, prints a likely hypothesis, links the right runbook, and
lists the next read-only Jeannie commands:
```bash
./jeannie incident replay
./jeannie incident triage --text "502 Bad Gateway from nginx"
```
Incident fixtures live under `infra/incident-commander`. Use them to turn
repeat outages into repeatable triage behavior before adding any self-healing.
## Safety Cases
Before high-blast-radius changes, generate a safety case from the Git diff:
```bash
./jeannie safety-case --since HEAD~1
```
It summarizes risk, blast radius, required validation, rollback, and forbidden
actions. The implementation lives under `infra/safety-cases` and reuses the
same impact rules as `./jeannie impact`.
## Agent Sandbox
Future Jeannie AI actions should be checked before execution. The local sandbox
policy starts with a read-only command classifier:
```bash
./jeannie agent-sandbox check "./jeannie status"
./jeannie agent-sandbox check "./jeannie nuke"
```
Policy is stored in `infra/agent-sandbox/policy.tsv`.
## AI Workload Scheduling
For AI-ish workloads, Jeannie can simulate placement across Debian, Pimox
workers, and the RPi based on CPU, memory, architecture, tailnet access, and
control-plane policy:
```bash
./jeannie ai-scheduler recommend small-rag
./jeannie ai-scheduler simulate
```
The simulator lives under `infra/ai-scheduler` and is a stepping stone toward a
real Kubernetes controller.
## Memory With Provenance
Jeannie can return cited retrieval context and check whether the local RAG index
is stale:
```bash
./jeannie ask --citations "how do I recover the cluster?"
./jeannie ai-memory check
```
This keeps local AI answers grounded in repo files and runbooks.
## Red/Blue Loop
Safe red-team/blue-team checks are grouped under one command:
```bash
./jeannie red-blue plan
./jeannie red-blue run --local
```
Local mode runs deterministic prompt-injection and eval checks. Live scans are
listed but gated so they can run from the Debian host when intended.
## Canary Promotion
The promotion helper defines release gates before production changes:
```bash
./jeannie promote plan
./jeannie promote validate
./jeannie promote rollback website-production
```
The current version is intentionally conservative: it validates local gates and
prints rollback steps while dev namespace automation remains explicit future
work.
## Guarded Self-Healing
Jeannie can turn status findings into an experimental self-heal plan:
```bash
./jeannie status --heal-plan
./jeannie status --heal
./jeannie heal apply --yes
```
Normal `status` remains read-only. The heal planner maps known findings to
guarded actions, chooses one highest-impact auto-eligible finding, checks the
proposed command against `infra/agent-sandbox/policy.tsv`, and runs only that
one action. Re-run `./jeannie status` after every heal cycle so Jeannie
can reassess before touching the next issue. If a specific Pimox worker is
NotReady, heal targets that worker with `./jeannie workers restart N`
instead of repeating a broad cluster start. After an action runs, Jeannie waits
for the target condition to clear and reports `healed` or `still failing`.
Failed heal actions are placed on a short cooldown so Jeannie does not loop on
the same VM restart; the next plan escalates to diagnostics instead.
Destructive actions remain blocked.
## Model Behavior Observatory
Stable prompts track local model behavior, latency, refusal behavior, and
tool-correctness signals over time:
```bash
./jeannie model-observe prompts
./jeannie model-observe run --offline
./jeannie model-observe report
```
Use `--live` only when Ollama is available.