Provider-agnostische LLM-Anbindung (Anthropic jetzt, Jetson/Ollama später per Env-Var umschaltbar). Stdlib-only Skripte + Beispiel-Workflows. GitLab-Duo-Parität für self-hosted Gitea + act_runner. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
2.7 KiB
Markdown
72 lines
2.7 KiB
Markdown
# ci-ai — KI-Schicht für die Gitea-CI
|
|
|
|
Self-hosted Äquivalent zu **GitLab Duo** für Gitea + act_runner: automatische
|
|
PR-Reviews, PR-Summaries, KI-erklärte Security-Funde und CI-Failure-Analyse.
|
|
Läuft über den vorhandenen `gitea-runner` auf dem Pi.
|
|
|
|
## Bausteine
|
|
|
|
| Feature | Skript | Trigger |
|
|
|---|---|---|
|
|
| A — PR-Review + Summary | `scripts/ai_review.py` | `pull_request` |
|
|
| B — Security-Scan + KI-Erklärung (hart blockierend) | `security.yml` + `scripts/ai_explain.py` | `pull_request`, `push` |
|
|
| C — CI-Failure-Analyse | `if:failure()`-Job + `scripts/ai_explain.py` | Job-Fehler |
|
|
|
|
`scripts/llm.py` ist die **provider-agnostische** LLM-Schicht — heute Claude
|
|
(Anthropic), später der lokale Jetson (Ollama), umschaltbar per Env-Var.
|
|
|
|
## Aufbau
|
|
|
|
```
|
|
scripts/
|
|
llm.py Provider-Abstraktion (anthropic | ollama), stdlib-only
|
|
gitea_api.py PR-Diff holen + idempotente Marker-Kommentare
|
|
context.py Gitea-Actions-Event-Kontext (GITHUB_*-Vars)
|
|
ai_review.py Feature A
|
|
ai_explain.py Features B & C
|
|
workflows/ Beispiel-Workflows zum Kopieren in Ziel-Repos
|
|
```
|
|
|
|
Keine Abhängigkeiten — reine Python-Standardbibliothek, kein `pip install`.
|
|
|
|
## In ein Repo einbauen
|
|
|
|
1. Beispiel aus `workflows/` nach `.gitea/workflows/` im Ziel-Repo kopieren.
|
|
2. Im Repo (oder org-weit) die **Actions-Unit** aktivieren.
|
|
3. **Actions-Secret** `ANTHROPIC_API_KEY` setzen. Kommentiert wird per Auto-Token
|
|
(`${{ github.token }}`); reichen dessen Rechte nicht, ein `GITEA_BOT_TOKEN`
|
|
(PAT mit `write:issue`) als Secret hinterlegen.
|
|
4. Für „hart blockieren": in der Branch-Protection den `Security`-Check als
|
|
*required* markieren.
|
|
|
|
## Umstieg auf den Jetson (später)
|
|
|
|
Sobald das lokale Ollama auf dem Jetson läuft — nur die Workflow-Env ändern,
|
|
**kein Code-Change**:
|
|
|
|
```yaml
|
|
AI_PROVIDER: ollama
|
|
AI_MODEL: qwen-light
|
|
AI_BASE_URL: http://192.168.178.20:11434/v1
|
|
JETSON_API_KEY: ${{ secrets.JETSON_API_KEY }}
|
|
```
|
|
|
|
## Konfiguration (Env-Vars)
|
|
|
|
| Var | Default | Zweck |
|
|
|---|---|---|
|
|
| `AI_PROVIDER` | `anthropic` | `anthropic` oder `ollama` |
|
|
| `AI_MODEL` | `claude-3-5-haiku-latest` / `qwen-light` | Modell |
|
|
| `ANTHROPIC_API_KEY` | — | Pflicht bei provider=anthropic |
|
|
| `AI_BASE_URL` | `http://192.168.178.20:11434/v1` | Ollama-Endpoint |
|
|
| `JETSON_API_KEY` | — | Bearer für Ollama (optional) |
|
|
| `GITEA_API` | `https://git.eulernest.eu/api/v1` | Gitea-API-Basis |
|
|
| `GITEA_TOKEN` / `GITEA_BOT_TOKEN` | — | Token fürs Kommentieren |
|
|
|
|
## Constraints
|
|
|
|
- Runner hat **capacity 1** → Jobs laufen seriell.
|
|
- Docker-Executor abgesichert (kein privileged, keine Host-Mounts) → Trivy
|
|
`fs`/`config` + Gitleaks laufen; Scans *laufender* Container nicht (unnötig).
|
|
- Kosten (Anthropic, Haiku-Klasse, gedeckelter Diff): Bruchteile eines Cent/PR.
|