feat: harden and extend the CLI (security, UX, robustness, tests)

Sieben Verbesserungen; die Dateien überschneiden sich thematisch, daher ein
Commit (jeder Commit bleibt grün: 115 Tests).

- #1 --check ist scriptbar: Exit 0 wenn Container läuft und erreichbar,
  sonst 5 (check_exit_code / CheckResult).
- #2 --force implementiert: Bypass eines belegten Locks mit Warnung
  (_container_lock) und stop_container(force=…) schluckt Inkonsistenzen.
- #3 stille Trunkierung behoben: chat_completion_text liefert ChatReply
  (content + finish_reason); bei finish_reason=length Hinweis auf stderr,
  --chat gibt Exit 1 bei leerem Content zurück.
- #4 keine vermeidbare Downtime: --change validiert den Modellpfad VOR dem
  Entfernen des laufenden Containers.
- #5 Netzwerk dicht: Port-Publish standardmäßig nur auf 127.0.0.1
  (--expose/expose für alle Interfaces), optionaler --api-key/api_key
  (Server --api-key + Bearer-Token auf allen Requests).
- #6 --stream: Chat-Reply token-weise via SSE auf stdout (stream_chat).
- #7 tests/test_actions.py: Orchestrierungs-Ebene (dry-run-Nebenwirkungen,
  Lock, validate-before-remove, chat/stream/exit-codes).

Doku aktualisiert (Manpage, README, llama.cpp.config.example).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-07-06 16:57:47 +02:00
commit 24202feee6
14 changed files with 485 additions and 32 deletions

View file

@ -23,7 +23,8 @@ an open port.
.TP
.B \-\-check
Report Docker container status, HTTP health/model endpoint reachability, and
(if a user prompt is supplied) whether a live chat completion succeeds.
(if a user prompt is supplied) whether a live chat completion succeeds. Exits
0 when the container is running and reachable, otherwise 5 (scriptable).
.TP
.B \-\-stop
Stop and remove the container. No-op if it does not exist.
@ -118,6 +119,16 @@ GPU device id passed to \fB\-\-gpus device=<ID>\fR.
.TP
.B \-\-restart\-policy \fIPOLICY\fR
Docker \fB\-\-restart\fR policy.
.TP
.B \-\-expose\fR / \fB\-\-no\-expose
Publish the port on all host interfaces (LAN-reachable) or on loopback only.
Default: loopback only, so the unauthenticated API is not exposed to the
network. Config key: \fBexpose\fR.
.TP
.B \-\-api\-key \fIKEY\fR
Require an API key on the server (\fB\-\-api\-key\fR) and send it as a Bearer
token on every request. Config key: \fBapi_key\fR. Recommended together with
\fB\-\-expose\fR.
.SS llama.cpp runtime parameters
.B \-\-ctx\-size\fR, \fB\-\-n\-predict\fR, \fB\-\-temp\fR, \fB\-\-top\-p\fR,
\fB\-\-top\-k\fR, \fB\-\-min\-p\fR, \fB\-\-repeat\-penalty\fR,
@ -143,6 +154,10 @@ answer, so a small budget yields empty content). Must be > 0.
.B \-\-chat\-temp \fIFLOAT\fR
Temperature for the chat request. If unset, the request omits temperature and
the server's configured \fB\-\-temp\fR applies (single source of truth).
.TP
.B \-\-stream
Stream the \fB\-\-chat\fR reply token-by-token to stdout as it is generated,
instead of waiting for the full response.
.SS Security / behavior flags (prompt input)
.TP
.B \-\-allow\-insecure\-http