Assistant IA optionnel (analyse de sortie, diagnostic, generation de commande)

Nouvelle couche app/ai/ (provider OpenAI-compatible via urllib, redaction de
secrets, detection de commandes dangereuses, parametres, worker QThread) et son
integration dans chaque onglet terminal via un bouton "Assistant IA" (memes
conventions que le bouton Snippets existant) :

- Expliquer cette sortie / Diagnostiquer cette erreur / Proposer une solution /
  Poser une question... : utilisent la selection courante du terminal, affichees
  dans un panneau lateral (memoire uniquement, jamais journalise) reutilisant le
  splitter comme le panneau SFTP.
- Generer une commande : ne s'execute jamais automatiquement (Copier / Inserer
  dans le terminal sans Entree / Annuler), avec avertissement si la commande
  proposee correspond a un motif destructeur connu.
- Avant tout envoi : avis unique (persist) puis detection de secrets evidents
  (mot de passe, cle, jeton) avec choix de masquer, envoyer tel quel ou annuler.

Desactive par defaut, sans liste de fournisseur figee (URL + modele libres,
compatible OpenAI/OpenRouter/LLM local). La cle API passe exclusivement par
CredentialStore (jamais dans settings.json ni journalisee). Parametrable via
le nouveau menu "Assistant IA > Parametres..." (bouton "Tester la connexion").

Bug trouve par les tests avant commit : un panneau nouvellement insere dans un
QSplitter deja visible est affiche automatiquement par Qt, ce qui inversait le
premier clic sur "Afficher le panneau IA" ; corrige en le masquant explicitement
a sa creation.

9 nouveaux fichiers de test (provider, redaction, dangers, parametres, worker,
confirmations de securite, dialogue de commande, panneau, integration onglet) :
39 verifications, toutes au vert. Suite complete (31 fichiers) executee sans
regression.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Florian
2026-09-05 05:48:13 +02:00
parent 9216f636bd
commit 0b2ff38bfd
22 changed files with 2081 additions and 8 deletions

View File

@@ -0,0 +1,60 @@
"""Detection/redaction de secrets avant envoi a l'assistant IA."""
import sys, pathlib
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent))
from app.ai.redaction import detect_secrets, redact
print("=== 1. Cle privee PEM detectee ===")
text = "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEA...\n-----END RSA PRIVATE KEY-----"
found = detect_secrets(text)
print(" detecte:", [f.label for f in found])
assert any("privee" in f.label.lower() for f in found)
print(" OK")
print()
print("=== 2. Jeton Bearer detecte ===")
found = detect_secrets("Authorization: Bearer sk-abcdefghijklmnopqrstuvwxyz123456")
labels = [f.label for f in found]
print(" detecte:", labels)
assert any("bearer" in l.lower() for l in labels)
assert any("authorization" in l.lower() for l in labels)
print(" OK")
print()
print("=== 3. Cle AWS detectee ===")
found = detect_secrets("export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE")
assert any("aws" in f.label.lower() for f in found)
print(" OK")
print()
print("=== 4. password= / api_key= / token= detectes ===")
assert any("mot de passe" in f.label.lower() for f in detect_secrets("password=Sup3rSecret!"))
assert any("api" in f.label.lower() for f in detect_secrets("api_key=abcd1234"))
assert any("jeton" in f.label.lower() for f in detect_secrets("token: eyJhbGciOiJIUzI1NiJ9"))
print(" OK")
print()
print("=== 5. Chaine longue ressemblant a un secret ===")
found = detect_secrets("valeur=" + "a1b2c3d4e5f6g7h8i9j0" * 3)
assert any("longue" in f.label.lower() for f in found)
print(" OK")
print()
print("=== 6. Texte anodin : rien detecte ===")
assert detect_secrets("systemd[1]: nginx.service: Failed with result 'exit-code'") == []
assert detect_secrets("nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)") == []
print(" OK")
print()
print("=== 7. redact() masque sans lever, texte anodin inchange ===")
redacted = redact("password=abc123 et Bearer xyzxyzxyzxyzxyzxyz")
print(" resultat:", redacted)
assert "abc123" not in redacted
assert "xyzxyzxyzxyzxyzxyz" not in redacted
assert "[MASQUE]" in redacted
clean = "systemctl status nginx"
assert redact(clean) == clean
print(" OK")
print()
print("AI REDACTION : TOUS LES TESTS OK")