feat(stt): auto-start via stt --install-service (phase 6)

Ajoute `stt --install-service` / `--uninstall-service` : génère et active un
service systemd --user (lié à graphical-session.target) qui lance le HUD + voix
à l'ouverture de session. Le kiosk existant (ui.kiosk) fournit l'« écran Jarvis ».

- cli : _service_unit (génération du unit, fonction pure testable),
  _cmd_install_service (écrit le unit + import-environment DISPLAY/WAYLAND +
  daemon-reload/enable/start), _cmd_uninstall_service.
- Docs : admin/ia/stt.md (phase 6 → , section Auto-start + caveat DISPLAY),
  stt/README.
- Bump client 0.2.1 → 0.3.0.

Phase 6 de la roadmap STT. Reste : test sur poste, outils Hermes (7).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Qjq5jHiqNepnobJpHYpCa
This commit is contained in:
Claude 2026-06-18 20:18:39 +00:00
parent 2658f92c2f
commit d1bf20c86d
No known key found for this signature in database
4 changed files with 131 additions and 9 deletions

View file

@ -1,6 +1,6 @@
[project]
name = "stt"
version = "0.2.1"
version = "0.3.0"
description = "STT — client vocal Jarvis du homelab Funk (voix + HUD, parle au STT-server)"
requires-python = ">=3.11"
readme = "README.md"

View file

@ -4,6 +4,7 @@ from __future__ import annotations
import argparse
import asyncio
import os
import sys
@ -22,6 +23,92 @@ def _cmd_setup() -> int:
return 0
SERVICE_NAME = "stt.service"
def _service_unit(stt_bin: str) -> str:
"""Contenu du unit systemd --user : lance `stt` (HUD + voix) avec la session graphique."""
return f"""[Unit]
Description=STT Assistant vocal Jarvis (HUD + voix)
After=graphical-session.target
PartOf=graphical-session.target
[Service]
Type=simple
ExecStart={stt_bin}
Restart=on-failure
RestartSec=5
Environment=PYTHONUNBUFFERED=1
StandardOutput=journal
StandardError=journal
SyslogIdentifier=stt
[Install]
WantedBy=graphical-session.target
"""
def _cmd_install_service() -> int:
"""Installe et démarre le service systemd --user (auto-start au login + kiosk)."""
import shutil
import subprocess
from pathlib import Path
stt_bin = shutil.which("stt") or os.path.realpath(sys.argv[0])
unit_dir = Path.home() / ".config" / "systemd" / "user"
unit_dir.mkdir(parents=True, exist_ok=True)
unit_path = unit_dir / SERVICE_NAME
unit_path.write_text(_service_unit(stt_bin))
print(f"✓ Unit écrit : {unit_path}")
print(f" ExecStart = {stt_bin}")
def sc(*args):
subprocess.run(["systemctl", "--user", *args], check=False)
# Rendre DISPLAY/WAYLAND dispo au gestionnaire systemd --user (pour le kiosk)
subprocess.run(
["systemctl", "--user", "import-environment",
"DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY"],
check=False,
)
sc("daemon-reload")
sc("enable", SERVICE_NAME)
sc("start", SERVICE_NAME)
print("\n✓ Service activé et démarré (systemd --user).")
print("\nCommandes utiles :")
print(" systemctl --user status stt")
print(" journalctl --user -u stt -f")
print(" systemctl --user restart stt")
print(" stt --uninstall-service")
print("\nDémarrer dès le boot (kiosk dédié, sans login manuel) :")
print(' sudo loginctl enable-linger "$USER" # + auto-login du bureau')
print("\nLe HUD s'ouvre en kiosk si [ui].kiosk = true (défaut).")
print("Si l'écran ne s'ouvre pas : voir le caveat DISPLAY dans admin/ia/stt.md.")
return 0
def _cmd_uninstall_service() -> int:
"""Arrête, désactive et supprime le service systemd --user."""
import subprocess
from pathlib import Path
def sc(*args):
subprocess.run(["systemctl", "--user", *args], check=False)
sc("stop", SERVICE_NAME)
sc("disable", SERVICE_NAME)
unit_path = Path.home() / ".config" / "systemd" / "user" / SERVICE_NAME
if unit_path.exists():
unit_path.unlink()
print(f"✓ Unit supprimé : {unit_path}")
else:
print("(unit déjà absent)")
sc("daemon-reload")
print("✓ Service STT désinstallé.")
return 0
def _make_client(args):
from stt.api import ServerClient
from stt.config import load_config, resolve_model
@ -116,10 +203,18 @@ def main(argv: list[str] | None = None) -> int:
p.add_argument("--model", help="Modèle : hermes, claude, qwen, opus (ou alias LiteLLM)")
p.add_argument("--server", help="Force l'URL du STT-server (sinon config)")
p.add_argument("--no-tts", action="store_true", help="Réponses texte seulement (voix)")
p.add_argument("--install-service", action="store_true",
help="Installe le service systemd --user (auto-start au login + kiosk)")
p.add_argument("--uninstall-service", action="store_true",
help="Désinstalle le service systemd --user")
args = p.parse_args(argv)
if args.setup:
return _cmd_setup()
if args.install_service:
return _cmd_install_service()
if args.uninstall_service:
return _cmd_uninstall_service()
if args.text:
return _cmd_text(args)
return _cmd_voice(args)