Mentor d'écriture (M1-M3) : coach dans les champs, relecture d'éditeur, méthode guidée « Donjon en 5 salles »
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Successful in 13m48s
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 13m16s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 3m3s
Build & Push Images / build (core) (push) Successful in 4m50s
Build & Push Images / build (web) (push) Successful in 3m26s
Build & Push Images / build-switcher (push) Successful in 26s
Build & Push Images / build (brain) (push) Canceled after 1m5s

- M1 coach : bouton ampoule sur 17 champs narratifs (scène, chapitre, arc),
  panneau de conseils (à quoi ça sert, questions, exemple, piège classique).
  Contenu statique i18n fr/en, sans IA ; ampoule aussi dans l'en-tête des
  sections repliables (input coachTopic d'expandable-section).
- M2 relecture d'éditeur : WritingReviewService + GET
  /api/campaigns/{id}/writing-review, 10 règles déterministes WRITE-001 à 010
  (couloir, faux choix, révélation à chemin unique, rythme monotone, enjeux
  absents, narration trop longue ou qui décide à la place des PJ, combat sans
  but, fin unique, scènes non typées). Le back renvoie ruleId + params, les
  textes fr/en sont dans l'i18n. Panneau sur le hub, encart dans les éditeurs,
  liens « Voir » avec ?focus= (nouveaux focus : narration, choices, stakes).
- M3 méthode guidée : POST /api/campaigns/{id}/guided-skeleton (arc existant
  ou nouveau, chapitre, scènes typées, chaînage optionnel, transactionnel)
  + assistant pas à pas générique /campaigns/:id/guided/:method, première
  méthode « Donjon en 5 salles ». Entrées sur le hub de campagne.
- Garde-fous vitest : complétude des textes fr/en du coach, de la relecture
  (règles lues dans le Java) et des méthodes guidées.

Vérifié : core clean verify (1182 tests), web build + 299 tests vitest, lint
sans erreur, parcours testés dans l'appli (back Postgres de dev).
À redéployer : core (2 endpoints, aucune migration) + web.
This commit is contained in:
2026-10-17 11:58:26 +02:00
parent ad3ea0e9e6
commit c2f162d823
59 changed files with 5533 additions and 40 deletions
@@ -1,17 +1,22 @@
<div class="expandable-section" [class.private]="variant === 'private'">
<button type="button" class="section-header" (click)="toggle()">
<span class="section-title">
@if (icon) {
<span class="section-icon">{{ icon }}</span>
}
{{ title }}
@if (filled) {
<span class="section-dot" aria-hidden="true"></span>
}
</span>
<lucide-icon [img]="isOpen ? ChevronUp : ChevronDown" [size]="16"></lucide-icon>
</button>
<div class="section-header-row">
<button type="button" class="section-header" (click)="toggle()">
<span class="section-title">
@if (icon) {
<span class="section-icon">{{ icon }}</span>
}
{{ title }}
@if (filled) {
<span class="section-dot" aria-hidden="true"></span>
}
</span>
<lucide-icon [img]="isOpen ? ChevronUp : ChevronDown" [size]="16"></lucide-icon>
</button>
@if (coachTopic) {
<app-writing-coach-trigger class="section-coach" [topic]="coachTopic"></app-writing-coach-trigger>
}
</div>
@if (isOpen) {
<div class="section-content">
@@ -9,12 +9,25 @@
&.private {
border-color: #7f1d1d;
.section-header { background: rgba(127, 29, 29, 0.12); }
.section-header-row { background: rgba(127, 29, 29, 0.12); }
.section-title { color: #fca5a5; }
}
}
// En-tête = bouton de repli + éventuel 💡 du coach d'écriture (bouton frère :
// pas de bouton imbriqué dans un bouton).
.section-header-row {
display: flex;
align-items: center;
}
.section-coach {
margin-right: 0.6rem;
}
.section-header {
flex: 1;
min-width: 0;
width: 100%;
display: flex;
align-items: center;
@@ -1,6 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { LucideAngularModule, ChevronDown, ChevronUp } from 'lucide-angular';
import { WritingCoachTriggerComponent } from '../writing-coach/writing-coach-trigger.component';
/**
* Section repliable avec titre (icône + texte) et contenu projeté via ng-content.
@@ -13,7 +14,7 @@ import { LucideAngularModule, ChevronDown, ChevronUp } from 'lucide-angular';
*/
@Component({
selector: 'app-expandable-section',
imports: [LucideAngularModule],
imports: [LucideAngularModule, WritingCoachTriggerComponent],
templateUrl: './expandable-section.component.html',
styleUrls: ['./expandable-section.component.scss']
})
@@ -31,6 +32,11 @@ export class ExpandableSectionComponent implements OnInit {
* sans avoir à les ouvrir une à une. Le parent calcule l'état.
*/
@Input() filled = false;
/**
* Sujet du coach d'écriture (ex. `scene.choices`) : affiche un 💡 dans l'en-tête
* qui ouvre les conseils. Pour les sections qui n'ont pas de libellé par champ.
*/
@Input() coachTopic: string | null = null;
isOpen = false;
@@ -0,0 +1,65 @@
import { readFileSync, readdirSync, statSync } from 'node:fs';
import { join } from 'node:path';
/**
* Garde-fou du contenu du coach d'écriture : chaque sujet référencé dans un
* template (`topic="…"` ou `coachTopic="…"`) doit exister en fr ET en en, avec
* ses 4 rubriques renseignées. Sinon le 💡 ouvrirait un panneau vide.
*/
const APP_DIR = join(process.cwd(), 'src/app');
const FRAGMENTS_DIR = join(process.cwd(), 'src/assets/i18n/fragments');
function htmlFiles(dir: string): string[] {
return readdirSync(dir).flatMap(name => {
const path = join(dir, name);
if (statSync(path).isDirectory()) return htmlFiles(path);
return name.endsWith('.html') ? [path] : [];
});
}
function referencedTopics(): string[] {
const topics = new Set<string>();
for (const file of htmlFiles(APP_DIR)) {
const html = readFileSync(file, 'utf-8');
for (const m of html.matchAll(/<app-writing-coach-trigger[^>]*\stopic="([^"]+)"/g)) topics.add(m[1]);
for (const m of html.matchAll(/\scoachTopic="([^"]+)"/g)) topics.add(m[1]);
}
return [...topics].sort();
}
function topicsOf(lang: 'fr' | 'en'): Record<string, Record<string, Record<string, unknown>>> {
const json = JSON.parse(readFileSync(join(FRAGMENTS_DIR, `writing-coach.${lang}.json`), 'utf-8'));
return json.writingCoach.topics;
}
function lookup(lang: 'fr' | 'en', key: string): Record<string, unknown> | undefined {
const [entity, field] = key.split('.');
return topicsOf(lang)[entity]?.[field];
}
describe('writing coach content', () => {
const topics = referencedTopics();
it('is referenced by the editors', () => {
expect(topics.length).toBeGreaterThan(0);
});
for (const lang of ['fr', 'en'] as const) {
it.each(topics)(`${lang}: topic %s is complete`, key => {
const topic = lookup(lang, key);
expect(topic, `writingCoach.topics.${key} manquant (${lang})`).toBeDefined();
for (const field of ['title', 'purpose', 'example', 'pitfall']) {
expect(typeof topic![field] === 'string' && (topic![field] as string).trim().length > 0,
`${key}.${field} vide (${lang})`).toBe(true);
}
const questions = topic!['questions'];
expect(Array.isArray(questions) && questions.length >= 2, `${key}.questions < 2 (${lang})`).toBe(true);
});
}
it('has the same topics in fr and en', () => {
const keys = (lang: 'fr' | 'en') => Object.entries(topicsOf(lang))
.flatMap(([entity, fields]) => Object.keys(fields).map(f => `${entity}.${f}`)).sort();
expect(keys('en')).toEqual(keys('fr'));
});
});
@@ -0,0 +1,57 @@
<aside class="coach-panel" [class.open]="!!topic()"
role="complementary"
[attr.aria-hidden]="!topic()"
[attr.aria-label]="'writingCoach.panelLabel' | translate">
@if (content(); as c) {
<header class="coach-header">
<div class="coach-heading">
<span class="coach-kicker">
<lucide-icon [img]="Lightbulb" [size]="14"></lucide-icon>
{{ 'writingCoach.kicker' | translate }}
</span>
<h2>{{ c.title }}</h2>
</div>
<button type="button" class="coach-close" (click)="close()"
[title]="'common.close' | translate" [attr.aria-label]="'common.close' | translate">
<lucide-icon [img]="X" [size]="16"></lucide-icon>
</button>
</header>
<div class="coach-body">
<section class="coach-block">
<h3>{{ 'writingCoach.purposeTitle' | translate }}</h3>
<p>{{ c.purpose }}</p>
</section>
@if (c.questions.length) {
<section class="coach-block">
<h3>{{ 'writingCoach.questionsTitle' | translate }}</h3>
<ul class="coach-questions">
@for (q of c.questions; track q) {
<li>{{ q }}</li>
}
</ul>
</section>
}
@if (c.example) {
<section class="coach-block coach-example">
<h3>{{ 'writingCoach.exampleTitle' | translate }}</h3>
<p>{{ c.example }}</p>
</section>
}
@if (c.pitfall) {
<section class="coach-block coach-pitfall">
<h3>{{ 'writingCoach.pitfallTitle' | translate }}</h3>
<p>{{ c.pitfall }}</p>
</section>
}
</div>
<footer class="coach-footer">
<p>{{ 'writingCoach.footer' | translate }}</p>
</footer>
}
</aside>
@@ -0,0 +1,154 @@
:host {
// Le panneau gère lui-même son positionnement fixed.
display: contents;
}
.coach-panel {
position: fixed;
top: 0;
right: 0;
width: min(380px, 100vw);
height: 100vh;
background: #0f0f1a;
border-left: 1px solid #1e1e3a;
box-shadow: -12px 0 32px rgba(0, 0, 0, 0.35);
display: flex;
flex-direction: column;
transform: translateX(100%);
visibility: hidden;
transition: transform 0.25s ease, visibility 0s linear 0.25s;
// Au-dessus du drawer de chat IA (1000) : c'est le dernier ouvert qui compte.
z-index: 1001;
&.open {
transform: translateX(0);
visibility: visible;
transition: transform 0.25s ease;
}
}
.coach-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 0.75rem;
padding: 1.1rem 1.25rem 1rem;
border-bottom: 1px solid #1e1e3a;
flex-shrink: 0;
h2 {
margin: 0.35rem 0 0;
font-size: 1.05rem;
font-weight: 600;
color: white;
}
}
.coach-kicker {
display: inline-flex;
align-items: center;
gap: 0.35rem;
font-size: 0.72rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
color: #fbbf24;
}
.coach-close {
display: inline-flex;
align-items: center;
justify-content: center;
width: 30px;
height: 30px;
flex-shrink: 0;
border-radius: 6px;
border: none;
background: transparent;
color: #9ca3af;
cursor: pointer;
&:hover { background: #1f2937; color: white; }
&:focus-visible { outline: 2px solid #6c63ff; }
}
.coach-body {
flex: 1;
overflow-y: auto;
padding: 1.1rem 1.25rem;
display: flex;
flex-direction: column;
gap: 1.25rem;
}
.coach-block {
h3 {
margin: 0 0 0.45rem;
font-size: 0.78rem;
font-weight: 600;
letter-spacing: 0.03em;
text-transform: uppercase;
color: #9ca3af;
}
p {
margin: 0;
font-size: 0.9rem;
line-height: 1.55;
color: #e5e7eb;
// Les exemples peuvent contenir des retours à la ligne (puces).
white-space: pre-line;
}
}
.coach-questions {
margin: 0;
padding-left: 1.1rem;
display: flex;
flex-direction: column;
gap: 0.5rem;
li {
font-size: 0.9rem;
line-height: 1.5;
color: #e5e7eb;
&::marker { color: #6c63ff; }
}
}
.coach-example {
padding: 0.85rem 1rem;
border-radius: 8px;
background: rgba(108, 99, 255, 0.08);
border: 1px solid rgba(108, 99, 255, 0.25);
p { font-style: italic; color: #d1d5db; }
}
.coach-pitfall {
padding: 0.85rem 1rem;
border-radius: 8px;
background: rgba(251, 191, 36, 0.06);
border: 1px solid rgba(251, 191, 36, 0.25);
h3 { color: #fbbf24; }
}
.coach-footer {
flex-shrink: 0;
padding: 0.85rem 1.25rem;
border-top: 1px solid #1e1e3a;
p {
margin: 0;
font-size: 0.78rem;
line-height: 1.5;
color: #6b7280;
}
}
@media (prefers-reduced-motion: reduce) {
.coach-panel,
.coach-panel.open { transition: none; }
}
@@ -0,0 +1,80 @@
import { Component, DestroyRef, HostListener, inject } from '@angular/core';
import { takeUntilDestroyed, toObservable, toSignal } from '@angular/core/rxjs-interop';
import { NavigationStart, Router } from '@angular/router';
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
import { filter, map, of, switchMap } from 'rxjs';
import { LucideAngularModule, Lightbulb, X } from 'lucide-angular';
import { WritingCoachService } from './writing-coach.service';
/** Fiche de conseils d'un champ, telle que rangée dans `writingCoach.topics.<clé>`. */
export interface WritingCoachTopic {
title: string;
purpose: string;
questions: string[];
example: string;
pitfall: string;
}
/**
* Panneau latéral du coach d'écriture, monté une seule fois dans le shell
* (comme `app-confirm-dialog-host`). Non modal : on peut continuer à écrire
* dans le formulaire pendant qu'il est ouvert.
*
* Posture « mentor d'abord » : il explique et questionne, il n'écrit jamais
* à la place du MJ (l'IA qui écrit reste le bouton « Étoffer avec l'IA »).
*/
@Component({
selector: 'app-writing-coach-panel',
imports: [LucideAngularModule, TranslatePipe],
templateUrl: './writing-coach-panel.component.html',
styleUrls: ['./writing-coach-panel.component.scss']
})
export class WritingCoachPanelComponent {
readonly Lightbulb = Lightbulb;
readonly X = X;
private readonly coach = inject(WritingCoachService);
private readonly translate = inject(TranslateService);
readonly topic = this.coach.topic;
/** Contenu du sujet ouvert, re-résolu au changement de langue. */
readonly content = toSignal(
toObservable(this.coach.topic).pipe(
switchMap(key => key
? this.translate.stream(`writingCoach.topics.${key}`).pipe(map(value => toTopic(value)))
: of(null))
),
{ initialValue: null }
);
constructor() {
// Changer d'écran ferme le panneau : ses conseils concernaient l'ancien formulaire.
inject(Router).events
.pipe(filter(e => e instanceof NavigationStart), takeUntilDestroyed(inject(DestroyRef)))
.subscribe(() => this.coach.close());
}
@HostListener('document:keydown.escape')
onEscape(): void {
if (this.coach.topic()) this.coach.close();
}
close(): void {
this.coach.close();
}
}
/** Clé absente → ngx-translate renvoie la clé elle-même (string) : on n'affiche rien. */
function toTopic(value: unknown): WritingCoachTopic | null {
if (!value || typeof value !== 'object') return null;
const t = value as Partial<WritingCoachTopic>;
return {
title: t.title ?? '',
purpose: t.purpose ?? '',
questions: Array.isArray(t.questions) ? t.questions : [],
example: t.example ?? '',
pitfall: t.pitfall ?? ''
};
}
@@ -0,0 +1,69 @@
import { Component, Input, computed, inject, signal } from '@angular/core';
import { TranslatePipe } from '@ngx-translate/core';
import { LucideAngularModule, Lightbulb } from 'lucide-angular';
import { WritingCoachService } from './writing-coach.service';
/**
* Petit bouton 💡 posé à côté d'un libellé de champ : ouvre le panneau de
* conseils d'écriture sur le sujet donné.
*
* Usage :
* <div class="field-label-row">
* <label for="x">Enjeux</label>
* <app-writing-coach-trigger topic="chapter.stakes"></app-writing-coach-trigger>
* </div>
*/
@Component({
selector: 'app-writing-coach-trigger',
imports: [LucideAngularModule, TranslatePipe],
template: `
<button type="button" class="coach-trigger"
[class.active]="active()"
[attr.aria-pressed]="active()"
[title]="'writingCoach.triggerTitle' | translate"
[attr.aria-label]="'writingCoach.triggerTitle' | translate"
(click)="onClick($event)">
<lucide-icon [img]="Lightbulb" [size]="14"></lucide-icon>
</button>
`,
styles: [`
:host { display: inline-flex; }
.coach-trigger {
display: inline-flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
padding: 0;
border-radius: 6px;
border: 1px solid transparent;
background: transparent;
color: #6b7280;
cursor: pointer;
transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.coach-trigger:hover { color: #fbbf24; background: rgba(251, 191, 36, 0.08); }
.coach-trigger:focus-visible { outline: 2px solid #6c63ff; outline-offset: 1px; }
.coach-trigger.active {
color: #fbbf24;
background: rgba(251, 191, 36, 0.12);
border-color: rgba(251, 191, 36, 0.4);
}
`]
})
export class WritingCoachTriggerComponent {
readonly Lightbulb = Lightbulb;
private readonly coach = inject(WritingCoachService);
private readonly topicKey = signal('');
@Input({ required: true }) set topic(value: string) { this.topicKey.set(value); }
readonly active = computed(() => this.coach.topic() === this.topicKey());
onClick(event: MouseEvent): void {
// Peut vivre dans l'en-tête d'une section repliable : ne pas la replier/déplier.
event.stopPropagation();
this.coach.toggle(this.topicKey());
}
}
@@ -0,0 +1,30 @@
import { Injectable, signal } from '@angular/core';
/**
* Coach d'écriture (Mentor d'écriture, phase M1 — voir docs/conception-mentor-ecriture.md).
*
* État global du panneau de conseils : un seul sujet ouvert à la fois, identifié
* par une clé « entité.champ » (ex. `scene.choices`) qui pointe vers
* `writingCoach.topics.<clé>` dans les fichiers i18n. Contenu 100 % statique :
* pas d'IA, pas d'appel réseau.
*/
@Injectable({ providedIn: 'root' })
export class WritingCoachService {
private readonly current = signal<string | null>(null);
/** Sujet actuellement affiché, ou null si le panneau est fermé. */
readonly topic = this.current.asReadonly();
open(topic: string): void {
this.current.set(topic);
}
close(): void {
this.current.set(null);
}
/** Re-cliquer sur le 💡 du sujet ouvert referme le panneau. */
toggle(topic: string): void {
this.current.set(this.current() === topic ? null : topic);
}
}
@@ -0,0 +1,87 @@
import { Component, Input, inject } from '@angular/core';
import { RouterLink } from '@angular/router';
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
import { LucideAngularModule, ArrowRight } from 'lucide-angular';
import { WritingRemark } from '../../services/writing-review.model';
import { remarkAction } from '../../campaigns/writing-remark-action.helper';
import { GapAction } from '../../campaigns/gap-action.helper';
/**
* Une remarque de relecture, en posture « mentor » : ce que j'observe, pourquoi
* ça compte, puis une question pour faire réfléchir (jamais de réécriture).
* Le texte vient de l'i18n `writingReview.rules.<ruleId>` ; le back fournit les paramètres.
*/
@Component({
selector: 'app-writing-remark-card',
imports: [RouterLink, TranslatePipe, LucideAngularModule],
template: `
<article class="remark">
<p class="remark-observation">{{ key('observation') | translate: textParams }}</p>
<p class="remark-why">{{ key('why') | translate: textParams }}</p>
<p class="remark-question">{{ key('question') | translate: textParams }}</p>
@if (showLink) {
<a class="remark-link" [routerLink]="action.link" [queryParams]="action.queryParams ?? null">
{{ 'writingReview.see' | translate }}
<lucide-icon [img]="ArrowRight" [size]="13"></lucide-icon>
</a>
}
</article>
`,
styles: [`
.remark {
display: flex;
flex-direction: column;
gap: 0.35rem;
padding: 0.8rem 0.95rem;
border-radius: 8px;
background: #111827;
border: 1px solid #1f2937;
border-left: 3px solid #fbbf24;
}
p { margin: 0; line-height: 1.5; }
.remark-observation { font-size: 0.88rem; font-weight: 600; color: #f3f4f6; }
.remark-why { font-size: 0.84rem; color: #9ca3af; }
.remark-question { font-size: 0.86rem; font-style: italic; color: #fcd34d; }
.remark-link {
align-self: flex-start;
display: inline-flex;
align-items: center;
gap: 0.3rem;
margin-top: 0.2rem;
font-size: 0.8rem;
font-weight: 600;
color: #a5b4fc;
text-decoration: none;
}
.remark-link:hover { color: #c7d2fe; text-decoration: underline; }
.remark-link:focus-visible { outline: 2px solid #6c63ff; outline-offset: 2px; border-radius: 4px; }
`]
})
export class WritingRemarkCardComponent {
readonly ArrowRight = ArrowRight;
private readonly translate = inject(TranslateService);
@Input({ required: true }) remark!: WritingRemark;
@Input() campaignId = '';
/** Lien vers l'éditeur concerné (inutile quand on est déjà dans cet éditeur). */
@Input() showLink = true;
key(part: 'observation' | 'why' | 'question'): string {
return `writingReview.rules.${this.remark.ruleId}.${part}`;
}
get action(): GapAction {
return remarkAction(this.remark, this.campaignId);
}
/** Paramètres du texte : ceux du back + le nom de l'entité + le genre de scène traduit. */
get textParams(): Record<string, string> {
const params: Record<string, string> = { ...this.remark.params, entity: this.remark.entityName ?? '' };
const kind = this.remark.params['kind'];
if (kind) {
params['kind'] = this.translate.instant(kind === 'COMBAT' ? 'writingReview.kindCombat' : `sceneType.${kind}`);
}
return params;
}
}
@@ -0,0 +1,74 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { remarkAction } from '../../campaigns/writing-remark-action.helper';
import { WritingRemark } from '../../services/writing-review.model';
/**
* Garde-fou de la relecture d'éditeur : chaque règle émise par le Core
* (WritingReviewService.java) doit avoir ses 3 textes en fr ET en en, sinon la
* carte afficherait des clés brutes.
*/
const SERVICE = join(process.cwd(), '../core/src/main/java/com/loremind/application/campaigncontext/WritingReviewService.java');
const FRAGMENTS_DIR = join(process.cwd(), 'src/assets/i18n/fragments');
function emittedRules(): string[] {
const java = readFileSync(SERVICE, 'utf-8');
return [...new Set([...java.matchAll(/"(WRITE-\d{3}-[A-Z-]+)"/g)].map(m => m[1]))].sort();
}
function rulesOf(lang: 'fr' | 'en'): Record<string, Record<string, string>> {
return JSON.parse(readFileSync(join(FRAGMENTS_DIR, `writing-review.${lang}.json`), 'utf-8')).writingReview.rules;
}
describe('writing review content', () => {
const rules = emittedRules();
it('finds the rules emitted by the core', () => {
expect(rules).toHaveLength(10);
});
for (const lang of ['fr', 'en'] as const) {
it.each(rules)(`${lang}: rule %s has its three texts`, ruleId => {
const texts = rulesOf(lang)[ruleId];
expect(texts, `${ruleId} manquant (${lang})`).toBeDefined();
for (const part of ['observation', 'why', 'question']) {
expect(texts[part]?.trim().length ?? 0, `${ruleId}.${part} vide (${lang})`).toBeGreaterThan(0);
}
});
}
it('has no orphan rule text', () => {
expect(Object.keys(rulesOf('fr')).sort()).toEqual(rules);
expect(Object.keys(rulesOf('en')).sort()).toEqual(rules);
});
});
describe('remarkAction', () => {
const base: WritingRemark = {
entityType: 'SCENE', entityId: 's1', ruleId: 'WRITE-007-NARRATION-DECIDES',
category: 'NARRATION', params: {}, arcId: 'a1', chapterId: 'c1'
};
it('opens the scene editor on the faulty section', () => {
expect(remarkAction(base, 'camp')).toEqual({
link: ['/campaigns', 'camp', 'arcs', 'a1', 'chapters', 'c1', 'scenes', 's1', 'edit'],
queryParams: { focus: 'narration' }
});
});
it('opens the chapter view for a corridor, the chapter editor for missing stakes', () => {
const chapter = { ...base, entityType: 'CHAPTER' as const, entityId: 'c1' };
expect(remarkAction({ ...chapter, ruleId: 'WRITE-001-CORRIDOR' }, 'camp').link)
.toEqual(['/campaigns', 'camp', 'arcs', 'a1', 'chapters', 'c1']);
expect(remarkAction({ ...chapter, ruleId: 'WRITE-005-NO-STAKES' }, 'camp')).toEqual({
link: ['/campaigns', 'camp', 'arcs', 'a1', 'chapters', 'c1', 'edit'],
queryParams: { focus: 'stakes' }
});
});
it('falls back to the campaign hub for campaign-wide remarks', () => {
const r = { ...base, entityType: 'CAMPAIGN' as const, entityId: 'camp', ruleId: 'WRITE-010-UNTYPED-SCENES' };
expect(remarkAction(r, 'camp').link).toEqual(['/campaigns', 'camp']);
});
});
@@ -0,0 +1,98 @@
import { Component, Input, OnChanges, SimpleChanges, inject } from '@angular/core';
import { TranslatePipe } from '@ngx-translate/core';
import { LucideAngularModule, ChevronDown, ChevronRight, Lightbulb } from 'lucide-angular';
import { ReadinessEntityType } from '../../services/readiness.model';
import { WritingRemark } from '../../services/writing-review.model';
import { WritingReviewService } from '../../services/writing-review.service';
import { WritingRemarkCardComponent } from './writing-remark-card.component';
/**
* Encart « Conseils de relecture » d'un éditeur (scène / chapitre / arc) : les remarques
* de la relecture d'éditeur qui concernent l'entité ouverte. Invisible s'il n'y en a pas.
*
* La relecture porte sur la version ENREGISTRÉE : après une sauvegarde, l'encart se met
* à jour au prochain chargement de l'éditeur.
*/
@Component({
selector: 'app-writing-review-hints',
imports: [TranslatePipe, LucideAngularModule, WritingRemarkCardComponent],
template: `
@if (remarks.length > 0) {
<section class="hints">
<button type="button" class="hints-header" (click)="open = !open" [attr.aria-expanded]="open">
<lucide-icon [img]="open ? ChevronDown : ChevronRight" [size]="15"></lucide-icon>
<lucide-icon [img]="Lightbulb" [size]="15" class="hints-icon"></lucide-icon>
<span>{{ 'writingReview.hintsTitle' | translate: { n: remarks.length } }}</span>
</button>
@if (open) {
<div class="hints-list">
@for (remark of remarks; track remark.ruleId) {
<app-writing-remark-card [remark]="remark" [campaignId]="campaignId" [showLink]="false">
</app-writing-remark-card>
}
</div>
}
</section>
}
`,
styles: [`
.hints {
background: rgba(251, 191, 36, 0.04);
border: 1px solid rgba(251, 191, 36, 0.25);
border-radius: 8px;
}
.hints-header {
display: flex;
align-items: center;
gap: 0.5rem;
width: 100%;
padding: 0.7rem 0.95rem;
background: transparent;
border: none;
border-radius: 8px;
color: #fde68a;
font-size: 0.88rem;
font-weight: 600;
cursor: pointer;
text-align: left;
}
.hints-header:hover { background: rgba(251, 191, 36, 0.06); }
.hints-header:focus-visible { outline: 2px solid #6c63ff; outline-offset: -2px; }
.hints-icon { color: #fbbf24; }
.hints-list {
display: flex;
flex-direction: column;
gap: 0.5rem;
padding: 0 0.95rem 0.95rem;
}
`]
})
export class WritingReviewHintsComponent implements OnChanges {
readonly ChevronDown = ChevronDown;
readonly ChevronRight = ChevronRight;
readonly Lightbulb = Lightbulb;
private readonly reviewService = inject(WritingReviewService);
@Input({ required: true }) campaignId = '';
@Input({ required: true }) entityType: ReadinessEntityType = 'SCENE';
@Input({ required: true }) entityId = '';
remarks: WritingRemark[] = [];
open = true;
ngOnChanges(changes: SimpleChanges): void {
if (!this.campaignId || !this.entityId) return;
if (changes['campaignId'] || changes['entityId'] || changes['entityType']) {
this.remarks = [];
const { entityType, entityId } = this;
this.reviewService.getReview(this.campaignId).subscribe({
next: report => {
this.remarks = report.remarks.filter(r => r.entityType === entityType && r.entityId === entityId);
},
error: () => { this.remarks = []; }
});
}
}
}
@@ -0,0 +1,37 @@
@if (report) {
<section class="review-panel">
<button type="button" class="review-header" (click)="toggle()" [attr.aria-expanded]="!collapsed">
<lucide-icon [img]="collapsed ? ChevronRight : ChevronDown" [size]="16"></lucide-icon>
<lucide-icon [img]="Lightbulb" [size]="16" class="review-icon"></lucide-icon>
<span class="review-title">{{ 'writingReview.title' | translate }}</span>
@if (total > 0) {
<span class="review-count">{{ 'writingReview.countN' | translate: { n: total } }}</span>
}
</button>
@if (!collapsed) {
<div class="review-body">
@if (total === 0) {
<p class="review-empty">{{ 'writingReview.allGood' | translate }}</p>
} @else {
<p class="review-intro">{{ 'writingReview.intro' | translate }}</p>
@for (group of groups; track group.category) {
<div class="review-group">
<h3>{{ ('writingReview.categories.' + group.category) | translate }}</h3>
<div class="review-list">
@for (remark of visible(group); track remark.ruleId + remark.entityId) {
<app-writing-remark-card [remark]="remark" [campaignId]="campaignId"></app-writing-remark-card>
}
</div>
@if (group.remarks.length > perGroup && !expanded.has(group.category)) {
<button type="button" class="review-more" (click)="showAll(group.category)">
{{ 'writingReview.showMore' | translate: { n: group.remarks.length - perGroup } }}
</button>
}
</div>
}
}
</div>
}
</section>
}
@@ -0,0 +1,92 @@
// Même gabarit que « Prochaines étapes » (readiness-panel), accent ambré du mentor.
.review-panel {
margin: 0 0 1.25rem;
background: #0d1117;
border: 1px solid #1f2937;
border-radius: 10px;
overflow: hidden;
}
.review-header {
display: flex;
align-items: center;
gap: 0.55rem;
width: 100%;
padding: 0.7rem 0.9rem;
background: transparent;
border: none;
color: #e5e7eb;
cursor: pointer;
text-align: left;
&:hover { background: #111827; }
&:focus-visible { outline: 2px solid #6c63ff; outline-offset: -2px; }
.review-icon { color: #fbbf24; }
}
.review-title {
font-weight: 600;
font-size: 0.92rem;
}
.review-count {
margin-left: auto;
padding: 0.1rem 0.5rem;
border-radius: 999px;
font-size: 0.72rem;
font-weight: 500;
background: #3a2e1a;
color: #fcd34d;
}
.review-body {
padding: 0 0.9rem 0.9rem;
display: flex;
flex-direction: column;
gap: 1rem;
}
.review-intro,
.review-empty {
margin: 0;
font-size: 0.85rem;
line-height: 1.5;
color: #9ca3af;
}
.review-empty { color: #86efac; }
.review-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
h3 {
margin: 0;
font-size: 0.75rem;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: uppercase;
color: #6b7280;
}
}
.review-list {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.review-more {
align-self: flex-start;
padding: 0.2rem 0;
border: none;
background: none;
color: #a5b4fc;
font-size: 0.8rem;
cursor: pointer;
&:hover { text-decoration: underline; }
&:focus-visible { outline: 2px solid #6c63ff; border-radius: 4px; }
}
@@ -0,0 +1,86 @@
import { Component, Input, OnChanges, SimpleChanges, inject } from '@angular/core';
import { TranslatePipe } from '@ngx-translate/core';
import { LucideAngularModule, ChevronDown, ChevronRight, Lightbulb } from 'lucide-angular';
import { WritingReviewService } from '../../services/writing-review.service';
import {
WRITING_REMARK_CATEGORIES, WritingRemark, WritingRemarkCategory, WritingReviewReport
} from '../../services/writing-review.model';
import { WritingRemarkCardComponent } from './writing-remark-card.component';
interface RemarkGroup {
category: WritingRemarkCategory;
remarks: WritingRemark[];
}
/**
* Panneau « Relecture d'éditeur » du hub campagne (Mentor d'écriture, phase M2) :
* le pendant « qualité » de « Prochaines étapes ». Conseils regroupés par famille,
* chacun avec son lien vers l'éditeur concerné. Purement indicatif.
*/
@Component({
selector: 'app-writing-review-panel',
imports: [TranslatePipe, LucideAngularModule, WritingRemarkCardComponent],
templateUrl: './writing-review-panel.component.html',
styleUrls: ['./writing-review-panel.component.scss']
})
export class WritingReviewPanelComponent implements OnChanges {
readonly ChevronDown = ChevronDown;
readonly ChevronRight = ChevronRight;
readonly Lightbulb = Lightbulb;
/** Remarques visibles par famille avant « voir les autres ». */
readonly perGroup = 3;
private static readonly STORAGE_KEY = 'loremind.writingReview.collapsed';
private readonly reviewService = inject(WritingReviewService);
@Input({ required: true }) campaignId = '';
report: WritingReviewReport | null = null;
groups: RemarkGroup[] = [];
expanded = new Set<WritingRemarkCategory>();
collapsed = readCollapsed();
ngOnChanges(changes: SimpleChanges): void {
if (changes['campaignId'] && this.campaignId) {
this.reviewService.getReview(this.campaignId).subscribe({
next: report => {
this.report = report;
this.groups = WRITING_REMARK_CATEGORIES
.map(category => ({ category, remarks: report.remarks.filter(r => r.category === category) }))
.filter(g => g.remarks.length > 0);
},
// Conseil facultatif : en cas d'erreur, le panneau ne s'affiche simplement pas.
error: () => { this.report = null; }
});
}
}
get total(): number {
return this.report?.remarks.length ?? 0;
}
toggle(): void {
this.collapsed = !this.collapsed;
try {
localStorage.setItem(WritingReviewPanelComponent.STORAGE_KEY, this.collapsed ? '1' : '0');
} catch { /* stockage indisponible : préférence non mémorisée */ }
}
visible(group: RemarkGroup): WritingRemark[] {
return this.expanded.has(group.category) ? group.remarks : group.remarks.slice(0, this.perGroup);
}
showAll(category: WritingRemarkCategory): void {
this.expanded.add(category);
}
}
function readCollapsed(): boolean {
try {
return localStorage.getItem('loremind.writingReview.collapsed') === '1';
} catch {
return false;
}
}