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
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user