Règles des systèmes en deux langues ; import de campagne dans la langue de l'UI
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 35s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 50s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 1m26s

- Règles d'un système de jeu stockées en français et en anglais (migration
  V28, rules_markdown_en). L'import d'un PDF garde l'extraction fidèle dans
  la langue du livre (détectée) et traduit section par section vers l'autre
  langue, noms propres conservés ; la progression de la traduction s'affiche.
  Un échec de traduction n'annule pas l'import.
- Éditeur du système : onglets Français / English ; l'import remplit les
  deux. Règles en séance et contexte de l'IA : version de la langue de
  l'interface, avec repli sur l'autre si elle est vide.
- Import de campagne : textes rédigés (ou traduits) dans la langue de
  l'interface ; titres et noms propres conservés tels quels ; arc par défaut
  nommé dans la bonne langue.
- Les règles anglaises suivent l'export/import de sauvegarde.

Vérifié : brain (détection, découpe, traduction, flux d'import, langue de
l'import de campagne), core clean verify (1299 tests), web build + vitest +
lint. Traduction non essayée avec un vrai modèle.
This commit is contained in:
2026-10-18 00:37:01 +02:00
parent a985bbd018
commit 007bcce8a7
34 changed files with 624 additions and 36 deletions
+14 -12
View File
@@ -361,7 +361,7 @@ class ImportCampaignUseCase:
# des appels LLM est divisé d'autant. 1 = comportement séquentiel.
self._map_concurrency = max(1, map_concurrency)
async def execute(self, pdf_bytes: bytes) -> CampaignImportResult:
async def execute(self, pdf_bytes: bytes, language: str = "fr") -> CampaignImportResult:
"""Variante non-streamée : traite tout puis renvoie l'arbre complet."""
doc = self._extractor.extract(pdf_bytes)
chunks = chunk_text(doc.full_text, self._chunk_target_tokens)
@@ -371,7 +371,7 @@ class ImportCampaignUseCase:
for start in range(0, total, self._map_concurrency):
wave = list(enumerate(chunks))[start:start + self._map_concurrency]
results = await asyncio.gather(*(
self._map_chunk(c, index=i, total=total, toc_block=toc_block)
self._map_chunk(c, index=i, total=total, toc_block=toc_block, language=language)
for i, c in wave
))
for res in results:
@@ -386,7 +386,7 @@ class ImportCampaignUseCase:
npcs=merger.npcs(),
)
async def stream(self, pdf_bytes: bytes):
async def stream(self, pdf_bytes: bytes, language: str = "fr"):
"""Variante streamée : yield des évènements d'avancement.
{"type":"extracting"}, puis {"type":"start", page_count, ocr_page_count,
@@ -432,7 +432,7 @@ class ImportCampaignUseCase:
for start in range(0, total, self._map_concurrency):
wave = list(enumerate(chunks))[start:start + self._map_concurrency]
gathered = asyncio.gather(
*(self._map_chunk(c, index=i, total=total, toc_block=toc_block)
*(self._map_chunk(c, index=i, total=total, toc_block=toc_block, language=language)
for i, c in wave),
return_exceptions=True,
)
@@ -553,21 +553,23 @@ class ImportCampaignUseCase:
# --- MAP : un morceau → sous-arbre ---------------------------------------
async def _map_chunk(
self, chunk: str, *, index: int, total: int, toc_block: str = ""
self, chunk: str, *, index: int, total: int, toc_block: str = "", language: str = "fr"
) -> dict:
"""Phase MAP d'un morceau → {"arcs": [...], "npcs": [...]}."""
return await self._extract_payload(
chunk, index=index, total=total, depth=0, toc_block=toc_block)
chunk, index=index, total=total, depth=0, toc_block=toc_block, language=language)
async def _extract_payload(
self, text: str, *, index: int, total: int, depth: int, toc_block: str = ""
self, text: str, *, index: int, total: int, depth: int, toc_block: str = "",
language: str = "fr",
) -> dict:
"""Extrait l'arborescence + les PNJ d'un texte. Si la SORTIE est tronquée,
retraite le texte en DEUX moitiés et concatène — le `_TreeMerger` final
dédoublonne par nom (un arc/chapitre coupé entre les moitiés est recollé)."""
toc_section = prompts.TOC_BLOCK.format(toc=toc_block) if toc_block else ""
prompt = (
prompts.MAP_SYSTEM.format(default_arc=prompts.DEFAULT_ARC_NAME)
prompts.MAP_SYSTEM.format(default_arc=prompts.default_arc_name(language))
+ prompts.language_block(language)
+ toc_section
+ f"\n\n--- EXTRAIT {index + 1}/{total} ---\n{text}\n\n"
"Renvoie maintenant le JSON de l'arborescence."
@@ -591,9 +593,9 @@ class ImportCampaignUseCase:
f"Le modèle est trop lent sur le morceau {index + 1} : "
"re-découpage en 2 moitiés plus digestes…")
a = await self._extract_payload(
left, index=index, total=total, depth=depth + 1, toc_block=toc_block)
left, index=index, total=total, depth=depth + 1, toc_block=toc_block, language=language)
b = await self._extract_payload(
right, index=index, total=total, depth=depth + 1, toc_block=toc_block)
right, index=index, total=total, depth=depth + 1, toc_block=toc_block, language=language)
return {"arcs": a["arcs"] + b["arcs"], "npcs": a["npcs"] + b["npcs"]}
payload, truncated = self._parse_payload(raw, index=index)
@@ -607,9 +609,9 @@ class ImportCampaignUseCase:
f"Réponse du modèle coupée sur le morceau {index + 1} : "
"re-découpage en 2 moitiés plus digestes…")
a = await self._extract_payload(
left, index=index, total=total, depth=depth + 1, toc_block=toc_block)
left, index=index, total=total, depth=depth + 1, toc_block=toc_block, language=language)
b = await self._extract_payload(
right, index=index, total=total, depth=depth + 1, toc_block=toc_block)
right, index=index, total=total, depth=depth + 1, toc_block=toc_block, language=language)
return {"arcs": a["arcs"] + b["arcs"], "npcs": a["npcs"] + b["npcs"]}
if truncated:
logger.warning(