-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
872 lines (691 loc) · 27.3 KB
/
install.ps1
File metadata and controls
872 lines (691 loc) · 27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
<#
.SYNOPSIS
Installe ou désinstalle le module Refactor dans un projet C++/Qt.
.DESCRIPTION
Ce script installe l'outil de refactoring assisté par IA dans le projet cible.
Il configure les commandes Claude Code, les prompts Copilot CLI et les agents GitHub Copilot.
Il peut également désinstaller complètement le module.
.PARAMETER ProjectPath
Chemin vers le répertoire du projet à analyser.
.PARAMETER SolutionFile
Chemin vers le fichier .sln (solution Visual Studio). Requis pour l'installation.
.PARAMETER BuildScript
Chemin vers le script PowerShell de build. Requis pour l'installation.
.PARAMETER UserName
Nom de l'utilisateur (optionnel, défaut: nom d'utilisateur Windows).
.PARAMETER Language
Langue de communication (optionnel, défaut: Français).
.PARAMETER Uninstall
Switch pour désinstaller le module du projet spécifié.
.EXAMPLE
.\install.ps1 -ProjectPath "C:\MonProjet" -SolutionFile "MonProjet.sln" -BuildScript "build.ps1"
Installe le module dans le projet.
.EXAMPLE
.\install.ps1 -ProjectPath "." -SolutionFile "App.sln" -BuildScript "scripts\build.ps1" -UserName "Karim"
Installe avec un nom d'utilisateur personnalisé.
.EXAMPLE
.\install.ps1 -Uninstall -ProjectPath "C:\MonProjet"
Désinstalle le module du projet.
#>
param(
[Parameter(Mandatory=$false, HelpMessage="Chemin vers le repertoire du projet")]
[string]$ProjectPath,
[Parameter(Mandatory=$false, HelpMessage="Fichier .sln (relatif au projet ou absolu)")]
[string]$SolutionFile,
[Parameter(Mandatory=$false, HelpMessage="Script PowerShell de build (relatif au projet ou absolu)")]
[string]$BuildScript,
[Parameter(Mandatory=$false)]
[string]$UserName = $env:USERNAME,
[Parameter(Mandatory=$false)]
[string]$Language = "Francais",
[Parameter(Mandatory=$false, HelpMessage="Desinstaller le module du projet")]
[switch]$Uninstall,
[Parameter(Mandatory=$false, HelpMessage="Force la desinstallation sans confirmation")]
[switch]$Force
)
# Couleurs pour l'affichage
function Write-Step { param($msg) Write-Host "[>] $msg" -ForegroundColor Cyan }
function Write-Success { param($msg) Write-Host "[OK] $msg" -ForegroundColor Green }
function Write-Info { param($msg) Write-Host " $msg" -ForegroundColor Gray }
function Write-Error { param($msg) Write-Host "[!!] $msg" -ForegroundColor Red }
function Write-Warning { param($msg) Write-Host "[!] $msg" -ForegroundColor Yellow }
# ============================================================================
# MODE DÉSINSTALLATION
# ============================================================================
if ($Uninstall) {
if (-not $ProjectPath) {
Write-Error "Le paramètre -ProjectPath est requis pour la désinstallation"
Write-Host "Usage: .\install.ps1 -Uninstall -ProjectPath ""C:\MonProjet""" -ForegroundColor Gray
exit 1
}
$ProjectPath = Resolve-Path $ProjectPath -ErrorAction SilentlyContinue
if (-not $ProjectPath) {
Write-Error "Le répertoire projet n'existe pas"
exit 1
}
Write-Host ""
Write-Host "+------------------------------------------------------------+" -ForegroundColor Red
Write-Host "| |" -ForegroundColor Red
Write-Host "| [X] REFACTOR MODULE - Desinstallation |" -ForegroundColor Red
Write-Host "| |" -ForegroundColor Red
Write-Host "+------------------------------------------------------------+" -ForegroundColor Red
Write-Host ""
Write-Info "Projet: $ProjectPath"
Write-Host ""
# Éléments à supprimer
$ItemsToRemove = @(
@{ Path = (Join-Path $ProjectPath ".refactor"); Type = "Dossier"; Desc = "Configuration et module" },
@{ Path = (Join-Path $ProjectPath ".claude\commands\refactor"); Type = "Dossier"; Desc = "Commandes Claude Code" },
@{ Path = (Join-Path $ProjectPath ".github\agents\refactor-rex.agent.md"); Type = "Fichier"; Desc = "Agent Rex" },
@{ Path = (Join-Path $ProjectPath ".github\agents\refactor-explain.agent.md"); Type = "Fichier"; Desc = "Agent Explain" },
@{ Path = (Join-Path $ProjectPath ".github\agents\refactor-propose.agent.md"); Type = "Fichier"; Desc = "Agent Propose" },
@{ Path = (Join-Path $ProjectPath ".github\agents\refactor-generate.agent.md"); Type = "Fichier"; Desc = "Agent Generate" },
@{ Path = (Join-Path $ProjectPath ".github\agents\refactor-score.agent.md"); Type = "Fichier"; Desc = "Agent Score" }
)
# Vérifier ce qui existe
$ExistingItems = @()
foreach ($Item in $ItemsToRemove) {
if (Test-Path $Item.Path) {
$ExistingItems += $Item
}
}
if ($ExistingItems.Count -eq 0) {
Write-Warning "Aucun fichier Refactor trouvé dans ce projet"
exit 0
}
# Afficher ce qui sera supprimé
Write-Step "Éléments à supprimer:"
Write-Host ""
foreach ($Item in $ExistingItems) {
$RelPath = $Item.Path -replace [regex]::Escape($ProjectPath), "."
Write-Host " [$($Item.Type)] $RelPath" -ForegroundColor White
Write-Info " $($Item.Desc)"
}
Write-Host ""
# Confirmation (sauf si -Force)
if (-not $Force) {
$Confirm = Read-Host "Confirmer la suppression ? (o/N)"
if ($Confirm -notmatch "^[oOyY]") {
Write-Warning "Desinstallation annulee"
exit 0
}
}
Write-Host ""
Write-Step "Suppression en cours..."
$Errors = 0
foreach ($Item in $ExistingItems) {
try {
if (Test-Path $Item.Path) {
Remove-Item -Path $Item.Path -Recurse -Force -ErrorAction Stop
$RelPath = $Item.Path -replace [regex]::Escape($ProjectPath), "."
Write-Success "Supprimé: $RelPath"
}
} catch {
Write-Error "Erreur: $($Item.Path) - $($_.Exception.Message)"
$Errors++
}
}
# Nettoyer les dossiers parents vides
$ParentDirs = @(
(Join-Path $ProjectPath ".claude\commands"),
(Join-Path $ProjectPath ".claude"),
(Join-Path $ProjectPath ".github\agents"),
(Join-Path $ProjectPath ".github")
)
foreach ($Dir in $ParentDirs) {
if ((Test-Path $Dir) -and ((Get-ChildItem $Dir -Force | Measure-Object).Count -eq 0)) {
Remove-Item -Path $Dir -Force -ErrorAction SilentlyContinue
$RelPath = $Dir -replace [regex]::Escape($ProjectPath), "."
Write-Info "Dossier vide supprimé: $RelPath"
}
}
Write-Host ""
if ($Errors -eq 0) {
Write-Host "+------------------------------------------------------------+" -ForegroundColor Green
Write-Host "| |" -ForegroundColor Green
Write-Host "| [OK] DESINSTALLATION TERMINEE |" -ForegroundColor Green
Write-Host "| |" -ForegroundColor Green
Write-Host "+------------------------------------------------------------+" -ForegroundColor Green
} else {
Write-Host "+------------------------------------------------------------+" -ForegroundColor Yellow
Write-Host "| |" -ForegroundColor Yellow
Write-Host "| [!] DESINSTALLATION PARTIELLE ($Errors erreur(s)) |" -ForegroundColor Yellow
Write-Host "| |" -ForegroundColor Yellow
Write-Host "+------------------------------------------------------------+" -ForegroundColor Yellow
}
Write-Host ""
exit $Errors
}
# ============================================================================
# MODE INSTALLATION
# ============================================================================
# Vérifier les paramètres obligatoires pour l'installation
if (-not $ProjectPath -or -not $SolutionFile -or -not $BuildScript) {
Write-Error "Paramètres manquants pour l'installation"
Write-Host ""
Write-Host "Usage:" -ForegroundColor Yellow
Write-Host " Installation:" -ForegroundColor Cyan
Write-Host " .\install.ps1 -ProjectPath ""C:\MonProjet"" -SolutionFile ""App.sln"" -BuildScript ""build.ps1""" -ForegroundColor White
Write-Host ""
Write-Host " Désinstallation:" -ForegroundColor Cyan
Write-Host " .\install.ps1 -Uninstall -ProjectPath ""C:\MonProjet""" -ForegroundColor White
Write-Host ""
exit 1
}
# Banner
Write-Host ""
Write-Host "+------------------------------------------------------------+" -ForegroundColor Yellow
Write-Host "| |" -ForegroundColor Yellow
Write-Host "| [*] REFACTOR MODULE - Installation |" -ForegroundColor Yellow
Write-Host "| |" -ForegroundColor Yellow
Write-Host "| L'IA conseille, l'humain decide |" -ForegroundColor Yellow
Write-Host "| |" -ForegroundColor Yellow
Write-Host "+------------------------------------------------------------+" -ForegroundColor Yellow
Write-Host ""
# Résoudre les chemins
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$ProjectPath = Resolve-Path $ProjectPath -ErrorAction SilentlyContinue
if (-not $ProjectPath) {
Write-Error "Le répertoire projet n'existe pas: $ProjectPath"
exit 1
}
Write-Step "Configuration"
Write-Info "Projet : $ProjectPath"
Write-Info "Solution : $SolutionFile"
Write-Info "Build : $BuildScript"
Write-Info "Utilisateur: $UserName"
Write-Info "Langue : $Language"
Write-Host ""
# Vérifier que les fichiers existent
$SlnPath = if ([System.IO.Path]::IsPathRooted($SolutionFile)) { $SolutionFile } else { Join-Path $ProjectPath $SolutionFile }
$BuildPath = if ([System.IO.Path]::IsPathRooted($BuildScript)) { $BuildScript } else { Join-Path $ProjectPath $BuildScript }
if (-not (Test-Path $SlnPath)) {
Write-Error "Fichier solution non trouvé: $SlnPath"
exit 1
}
if (-not (Test-Path $BuildPath)) {
Write-Error "Script de build non trouvé: $BuildPath"
exit 1
}
Write-Success "Fichiers vérifiés"
# Créer les répertoires
Write-Step "Création de la structure"
$RefactorDir = Join-Path $ProjectPath ".refactor"
$ClaudeDir = Join-Path $ProjectPath ".claude\commands\refactor"
$GitHubAgentsDir = Join-Path $ProjectPath ".github\agents"
$Dirs = @(
$RefactorDir,
(Join-Path $RefactorDir "module"),
(Join-Path $RefactorDir "module\agents"),
(Join-Path $RefactorDir "module\workflows\explain"),
(Join-Path $RefactorDir "module\workflows\propose"),
(Join-Path $RefactorDir "module\workflows\generate"),
(Join-Path $RefactorDir "module\workflows\score"),
(Join-Path $RefactorDir "module\data"),
(Join-Path $RefactorDir "backup"),
$ClaudeDir,
$GitHubAgentsDir
)
foreach ($Dir in $Dirs) {
if (-not (Test-Path $Dir)) {
New-Item -ItemType Directory -Path $Dir -Force | Out-Null
}
}
Write-Success "Structure créée"
# Copier les fichiers du module
Write-Step "Installation du module"
$SourceModule = Join-Path $ScriptDir "refactor"
if (Test-Path $SourceModule) {
Copy-Item -Path "$SourceModule\*" -Destination (Join-Path $RefactorDir "module") -Recurse -Force
Write-Success "Module copié"
} else {
Write-Error "Dossier source 'refactor' non trouvé dans: $ScriptDir"
exit 1
}
# Générer la configuration
Write-Step "Génération de la configuration"
$ConfigContent = @"
# Refactor Module - Configuration
# Généré le $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
module_name: refactor
version: "1.0.0"
# Utilisateur
user:
name: "$UserName"
language: "$Language"
# Projet
project:
path: "$($ProjectPath -replace '\\', '/')"
solution: "$($SolutionFile -replace '\\', '/')"
build_script: "$($BuildScript -replace '\\', '/')"
build_command: "powershell.exe -ExecutionPolicy Bypass -File $($BuildScript -replace '\\', '/') -Configuration Debug"
file_extensions:
- ".cpp"
- ".h"
- ".hpp"
- ".cc"
# Chemins
paths:
module: ".refactor/module"
artifacts: ".refactor"
backup: ".refactor/backup"
# Paramètres
defaults:
max_file_lines: 4000
max_retries: 3
mode: "safe"
# Qt
qt:
enabled: true
constraints:
protect_q_object: true
protect_signals_slots: true
exclude_ui_files: true
"@
$ConfigPath = Join-Path $RefactorDir "config.yaml"
$ConfigContent | Out-File -FilePath $ConfigPath -Encoding utf8
Write-Success "Configuration générée: .refactor/config.yaml"
# Générer les commandes Claude Code
Write-Step "Installation des commandes Claude Code"
# /refactor
$CmdRefactor = @'
# /refactor - Agent Refactoring
Lance l'agent Rex pour le refactoring de code C++/Qt legacy.
## Activation
1. **Charge la configuration** : `.refactor/config.yaml`
2. **Charge l'agent** : `.refactor/module/agents/refactorer.md`
3. **Affiche le menu** et attends le choix
## Menu
```
Bonjour {user.name} ! Je suis Rex, ton conseiller en refactoring.
[1] EXPLAIN - Comprendre le code
[2] PROPOSE - Suggérer des refactorings
[3] GENERATE - Appliquer les transformations
[4] SCORE - Mesurer le gain
[0] QUIT - Quitter
```
## Pipeline
```
EXPLAIN -> PROPOSE -> GENERATE -> SCORE
| | | |
HUMAIN HUMAIN HUMAIN HUMAIN
```
L'IA conseille, l'humain decide.
'@
# /refactor:explain
$CmdExplain = @'
# /refactor:explain - Analyser le code
## Usage
```
/refactor:explain <fichier>
/refactor:explain <fichier>:100-200
/refactor:explain <fichier>::MaClasse
/refactor:explain <fichier> --focus "description"
```
## Exécution
1. Charge `.refactor/config.yaml`
2. Parse l'argument : $ARGUMENTS
3. Exécute `.refactor/module/workflows/explain/instructions.md`
4. Sauvegarde dans `.refactor/analysis.md`
## Output
- Vue d'ensemble du code
- Structure (classes, méthodes)
- Dette technique détectée
- Recommandations
'@
# /refactor:propose
$CmdPropose = @'
# /refactor:propose - Suggérer des refactorings
## Usage
```
/refactor:propose
/refactor:propose --mode deep
/refactor:propose --focus "rendre testable"
```
## Options
- `--mode safe` (défaut) : Renommages, extractions
- `--mode deep` : Split classe, changement signature
- `--focus "..."` : Orientation spécifique
## Prérequis
`.refactor/analysis.md` doit exister (lancer EXPLAIN d'abord)
## Exécution
1. Charge `.refactor/config.yaml`
2. Vérifie analysis.md existe
3. Exécute `.refactor/module/workflows/propose/instructions.md`
4. Sauvegarde `.refactor/proposal.md` et `.refactor/proposal.json`
'@
# /refactor:generate
$CmdGenerate = @'
# /refactor:generate - Appliquer les transformations
## Usage
```
/refactor:generate 1
/refactor:generate 1,3,4
/refactor:generate all
```
## Prérequis
`.refactor/proposal.json` doit exister (lancer PROPOSE d'abord)
## Comportement
1. Backup automatique avant modification
2. Résolution des dépendances
3. Compilation après transformation
4. Retry si erreur (max 3)
5. Rollback si échec
## Exécution
1. Charge `.refactor/config.yaml`
2. Parse les steps : $ARGUMENTS
3. Exécute `.refactor/module/workflows/generate/instructions.md`
4. Sauvegarde `.refactor/generate-report.md`
'@
# /refactor:score
$CmdScore = @'
# /refactor:score - Mesurer le gain
## Usage
```
/refactor:score
```
## Prérequis
Un backup doit exister (lancer GENERATE d'abord)
## Métriques
- Complexité cyclomatique
- Lignes de code
- Score global (0-100)
## Exécution
1. Charge `.refactor/config.yaml`
2. Exécute `.refactor/module/workflows/score/instructions.md`
3. Sauvegarde `.refactor/score-report.md`
'@
$CmdRefactor | Out-File -FilePath (Join-Path $ClaudeDir "refactor.md") -Encoding utf8
$CmdExplain | Out-File -FilePath (Join-Path $ClaudeDir "explain.md") -Encoding utf8
$CmdPropose | Out-File -FilePath (Join-Path $ClaudeDir "propose.md") -Encoding utf8
$CmdGenerate | Out-File -FilePath (Join-Path $ClaudeDir "generate.md") -Encoding utf8
$CmdScore | Out-File -FilePath (Join-Path $ClaudeDir "score.md") -Encoding utf8
Write-Success "Commandes Claude Code installées: .claude/commands/refactor/"
# Générer les agents GitHub Copilot
Write-Step "Installation des agents GitHub Copilot"
# Agent principal - Rex
$AgentRex = @"
---
name: Rex
description: Expert en refactoring C++/Qt pour réduire la dette technique
---
Tu es **Rex**, un expert senior en refactoring avec 15+ ans d'expérience en C++/Qt.
## Identité
- **Rôle**: Expert Senior en Refactoring et Dette Technique
- **Style**: Direct et pragmatique. Explique le "pourquoi" autant que le "quoi".
- **Philosophie**: "L'IA conseille, l'humain décide"
## Contexte Projet
- **Solution**: $SolutionFile
- **Build**: ``powershell.exe -ExecutionPolicy Bypass -File $BuildScript -Configuration Debug``
- **Configuration**: ``.refactor/config.yaml``
- **Langue**: $Language
## Capacités
Tu aides les développeurs à travers le pipeline de refactoring:
### 1. EXPLAIN - Comprendre le code
Analyse un fichier/scope pour identifier:
- Structure (classes, méthodes, dépendances)
- Dette technique (couplage, SRP, testabilité)
- Métriques (complexité cyclomatique, lignes)
- **Output**: ``.refactor/analysis.md``
### 2. PROPOSE - Suggérer des refactorings
Génère des propositions justifiées:
- **Mode safe**: renommages, extractions, code mort (risque faible)
- **Mode deep**: split classe, changement signature (risque moyen)
- **Output**: ``.refactor/proposal.md`` + ``.refactor/proposal.json``
### 3. GENERATE - Appliquer les transformations
Exécute les refactorings sélectionnés:
- Backup automatique avant modification
- Résolution des dépendances
- Compilation et retry si erreur
- Rollback si échec
- **Output**: ``.refactor/generate-report.md``
### 4. SCORE - Mesurer le gain
Compare avant/après:
- Complexité cyclomatique
- Lignes de code
- Score global (0-100)
- **Output**: ``.refactor/score-report.md``
## Contraintes Qt
- **JAMAIS** déplacer ``Q_OBJECT`` sans régénérer MOC
- **JAMAIS** modifier les signatures de signals/slots existants
- **IGNORER** les fichiers ``ui_*.h`` (générés)
- Avertir si un refactoring impacte la génération MOC
## Principes
1. L'objectif n'est pas la perfection, c'est de rendre le code "travaillable"
2. Ne jamais rajouter de la dette sur de la dette
3. Chaque transformation doit compiler avant de passer à la suivante
4. Transparence totale sur les risques
## Pipeline
``````
EXPLAIN -> PROPOSE -> GENERATE -> SCORE
| | | |
HUMAIN HUMAIN HUMAIN HUMAIN
LIT DECIDE REVIEW JUGE
``````
**Chaque etape requiert une decision humaine.**
## Comment m'utiliser
1. Dis-moi quel fichier tu veux analyser
2. Je t'explique sa structure et ses problèmes
3. Je te propose des refactorings avec justifications
4. Tu choisis lesquels appliquer
5. J'exécute et je mesure le gain
Communique en $Language.
"@
# Agent Explain
$AgentExplain = @"
---
name: Rex-Explain
description: Analyse et comprend le code C++/Qt pour identifier la dette technique
---
Tu es **Rex** en mode **EXPLAIN** - Analyse de code.
## Mission
Analyser un fichier ou scope de code C++/Qt pour comprendre:
- Sa structure (classes, méthodes, dépendances)
- Ses patterns et idiomes
- Sa dette technique
- Ses métriques de complexité
## Contexte
- **Solution**: $SolutionFile
- **Configuration**: ``.refactor/config.yaml``
## Instructions
1. **Lis le fichier/scope** demandé complètement
2. **Analyse la structure**:
- Classes et leurs responsabilités
- Méthodes principales
- Dépendances (includes)
3. **Identifie la dette technique**:
- 🔴 Critique: couplage fort, God classes, non-testable
- 🟡 Modéré: noms obscurs, fonctions longues
- 🟢 Suggestions: améliorations possibles
4. **Calcule les métriques**:
- Complexité cyclomatique par fonction
- Lignes par fonction
- Niveau de couplage
5. **Génère le rapport** dans ``.refactor/analysis.md``
## Contraintes Qt
Note les éléments Qt spécifiques:
- Macros ``Q_OBJECT``
- Signals/Slots
- Fichiers .ui associés
## Output
Crée ``.refactor/analysis.md`` avec:
- Vue d'ensemble
- Structure détaillée
- Dette technique classifiée
- Recommandations
Communique en $Language.
"@
# Agent Propose
$AgentPropose = @"
---
name: Rex-Propose
description: Suggère des refactorings justifiés pour code C++/Qt
---
Tu es **Rex** en mode **PROPOSE** - Suggestions de refactoring.
## Mission
Analyser le code et proposer des refactorings justifiés avec:
- Identification du type (extract_method, rename, split_class...)
- Niveau de risque (low/medium/high)
- Justification avec métriques
- Dépendances entre propositions
## Prérequis
- ``.refactor/analysis.md`` doit exister (lancer EXPLAIN d'abord)
## Modes
### Mode SAFE (défaut, risque faible)
- Renommer variables/méthodes obscures
- Extraire méthodes privées
- Supprimer code mort
- Simplifier conditions (guard clauses)
### Mode DEEP (risque moyen)
- Changer signatures publiques
- Séparer classes (SRP)
- Extraire interfaces
- Modifier héritage
## Contraintes Qt
- **JAMAIS** proposer de déplacer ``Q_OBJECT``
- **JAMAIS** proposer de modifier signatures signals/slots
- Ignorer fichiers ``ui_*.h``
## Output
1. ``.refactor/proposal.md`` - Propositions lisibles:
- ID, titre, type
- Risque avec emoji (🟢/🟡/🔴)
- Justification
- Dépendances
2. ``.refactor/proposal.json`` - Structure parsable
Communique en $Language.
"@
# Agent Generate
$AgentGenerate = @"
---
name: Rex-Generate
description: Applique les refactorings sélectionnés sur code C++/Qt
---
Tu es **Rex** en mode **GENERATE** - Application des transformations.
## Mission
Appliquer les refactorings sélectionnés de manière sécurisée:
1. Créer un backup
2. Résoudre les dépendances
3. Appliquer les transformations
4. Compiler
5. Corriger si erreur (max 3 tentatives)
6. Rollback si échec
## Prérequis
- ``.refactor/proposal.json`` doit exister
## Configuration
- **Build**: ``powershell.exe -ExecutionPolicy Bypass -File $BuildScript -Configuration Debug``
- **Max retries**: 3
## Processus
1. **BACKUP**: Copie dans ``.refactor/backup/{timestamp}/``
2. **DÉPENDANCES**: Vérifie et résout (tri topologique)
3. **TRANSFORMATION**: Applique chaque step
4. **COMPILATION**: Exécute ``powershell.exe -ExecutionPolicy Bypass -File $BuildScript -Configuration Debug``
5. **CORRECTION**: Si erreur, analyse et corrige
6. **ROLLBACK**: Si échec après 3 tentatives, restaure
## Contraintes Qt
- Protège ``Q_OBJECT``
- Protège signatures signals/slots
- Met à jour fichiers projet si nouveaux fichiers créés
## Output
``.refactor/generate-report.md`` avec:
- Steps appliqués
- Fichiers modifiés
- Commit message suggéré
- Chemin du backup
Communique en $Language.
"@
# Agent Score
$AgentScore = @"
---
name: Rex-Score
description: Mesure le gain du refactoring sur code C++/Qt
---
Tu es **Rex** en mode **SCORE** - Mesure du gain.
## Mission
Comparer l'état actuel avec le backup pour mesurer objectivement le gain:
- Complexité cyclomatique
- Lignes de code
- Qualité globale
## Prérequis
- Un backup doit exister dans ``.refactor/backup/``
## Métriques
| Métrique | Poids |
|----------|-------|
| Δ Complexité cyclomatique | 40% |
| Δ Lignes de code | 20% |
| Δ Fonctions/méthodes | 20% |
| Qualité subjective | 20% |
## Score
| Score | Verdict |
|-------|---------|
| 90-100 | Amélioration exceptionnelle |
| 70-89 | Amélioration significative |
| 50-69 | Amélioration modérée |
| 30-49 | Amélioration légère |
| 0-29 | Peu d'amélioration |
## Output
``.refactor/score-report.md`` avec:
- Score global
- Métriques détaillées
- Analyse qualitative
- Recommandations
Communique en $Language.
"@
# Écrire les agents
$AgentRex | Out-File -FilePath (Join-Path $GitHubAgentsDir "refactor-rex.agent.md") -Encoding utf8
$AgentExplain | Out-File -FilePath (Join-Path $GitHubAgentsDir "refactor-explain.agent.md") -Encoding utf8
$AgentPropose | Out-File -FilePath (Join-Path $GitHubAgentsDir "refactor-propose.agent.md") -Encoding utf8
$AgentGenerate | Out-File -FilePath (Join-Path $GitHubAgentsDir "refactor-generate.agent.md") -Encoding utf8
$AgentScore | Out-File -FilePath (Join-Path $GitHubAgentsDir "refactor-score.agent.md") -Encoding utf8
Write-Success "Agents GitHub Copilot installés: .github/agents/"
# Resume final
Write-Host ""
Write-Host "+------------------------------------------------------------+" -ForegroundColor Green
Write-Host "| |" -ForegroundColor Green
Write-Host "| [OK] INSTALLATION TERMINEE |" -ForegroundColor Green
Write-Host "| |" -ForegroundColor Green
Write-Host "+------------------------------------------------------------+" -ForegroundColor Green
Write-Host ""
Write-Host "Fichiers installes:" -ForegroundColor Yellow
Write-Host ""
Write-Host " .refactor/" -ForegroundColor White
Write-Host " +-- config.yaml # Configuration" -ForegroundColor Gray
Write-Host " +-- module/ # Module complet" -ForegroundColor Gray
Write-Host " +-- backup/ # Sauvegardes" -ForegroundColor Gray
Write-Host ""
Write-Host " .claude/commands/refactor/ # Commandes Claude Code" -ForegroundColor White
Write-Host " +-- refactor.md" -ForegroundColor Gray
Write-Host " +-- explain.md" -ForegroundColor Gray
Write-Host " +-- propose.md" -ForegroundColor Gray
Write-Host " +-- generate.md" -ForegroundColor Gray
Write-Host " +-- score.md" -ForegroundColor Gray
Write-Host ""
Write-Host " .github/agents/ # Agents GitHub Copilot" -ForegroundColor White
Write-Host " +-- refactor-rex.agent.md # Agent principal" -ForegroundColor Gray
Write-Host " +-- refactor-explain.agent.md" -ForegroundColor Gray
Write-Host " +-- refactor-propose.agent.md" -ForegroundColor Gray
Write-Host " +-- refactor-generate.agent.md" -ForegroundColor Gray
Write-Host " +-- refactor-score.agent.md" -ForegroundColor Gray
Write-Host ""
Write-Host "Utilisation:" -ForegroundColor Yellow
Write-Host ""
Write-Host " CLAUDE CODE:" -ForegroundColor Cyan
Write-Host " /refactor # Lance l'agent Rex" -ForegroundColor White
Write-Host " /refactor:explain File.cpp # Analyser" -ForegroundColor White
Write-Host " /refactor:propose # Suggérer" -ForegroundColor White
Write-Host " /refactor:generate 1,3 # Appliquer" -ForegroundColor White
Write-Host " /refactor:score # Mesurer" -ForegroundColor White
Write-Host ""
Write-Host " GITHUB COPILOT:" -ForegroundColor Cyan
Write-Host " @refactor-rex # Agent principal" -ForegroundColor White
Write-Host " @refactor-explain # Analyser" -ForegroundColor White
Write-Host " @refactor-propose # Suggérer" -ForegroundColor White
Write-Host " @refactor-generate # Appliquer" -ForegroundColor White
Write-Host " @refactor-score # Mesurer" -ForegroundColor White
Write-Host ""
Write-Host "Pipeline:" -ForegroundColor Yellow
Write-Host " EXPLAIN -> PROPOSE -> GENERATE -> SCORE" -ForegroundColor White
Write-Host " | | | |" -ForegroundColor Gray
Write-Host " HUMAIN HUMAIN HUMAIN HUMAIN" -ForegroundColor Gray
Write-Host ""
Write-Host " L'IA conseille, l'humain decide." -ForegroundColor Magenta
Write-Host ""