Capitalise nouveaux patterns backend/frontend/BMAD et externalise les templates du post-install BMAD

This commit is contained in:
MaksTinyWorkshop
2026-03-10 10:52:07 +01:00
parent 4a3df7cd01
commit f7a55b1113
23 changed files with 742 additions and 220 deletions

View File

@@ -5,16 +5,7 @@
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Résolution du chemin Lead_tech (même logique que aliases.sh)
if [ -d "$HOME/AI_RULES/_Assistant_Lead_Tech" ]; then
LEADTECH_PATH="$HOME/AI_RULES/_Assistant_Lead_Tech"
elif [ -d "/srv/projects/_Assistant_Lead_Tech" ]; then
LEADTECH_PATH="/srv/projects/_Assistant_Lead_Tech"
else
echo "Erreur : impossible de localiser le repo Lead_tech." >&2
exit 1
fi
TEMPLATES_DIR="$SCRIPT_DIR/../70_templates/bmad_post_install"
# Projet courant
PROJECT_ROOT="$(pwd)"
@@ -22,224 +13,201 @@ PROJECT_NAME="$(basename "$PROJECT_ROOT")"
AGENTS_DIR="$PROJECT_ROOT/_bmad/_config/agents"
CLAUDE_MD="$PROJECT_ROOT/CLAUDE.md"
if [ ! -d "$AGENTS_DIR" ]; then
echo "Erreur : dossier _bmad/_config/agents/ introuvable dans $PROJECT_ROOT"
echo "Lance ce script depuis la racine d'un projet BMAD installé."
exit 1
fi
# Agents à patcher
# Tous les agents susceptibles d'identifier un pattern, anti-pattern ou décision réutilisable
PRODUCER_AGENTS=(
"bmm-dev"
"bmm-architect"
"bmm-sm"
"bmm-qa"
"bmm-quick-flow-solo-dev"
"bmm-analyst"
"bmm-pm"
"bmm-tech-writer"
"bmm-ux-designer"
"tea-tea"
"core-bmad-master"
)
CAPITALIZE_MARKER="95_a_capitaliser.md"
patch_agent() {
local agent="$1"
local file="$AGENTS_DIR/${agent}.customize.yaml"
if [ ! -f "$file" ]; then
return 0 # agent non installé dans ce projet, on skip
fi
# Idempotent : ne pas injecter si déjà présent
if grep -q "$CAPITALIZE_MARKER" "$file"; then
echo " [skip] $agent — memory déjà présente"
return 0
fi
# Injection après la ligne "memories: []"
# Si memories: [] → remplacer par le bloc memories avec la memory
if grep -q "^memories: \[\]" "$file"; then
# Construire la memory adaptée au rôle de l'agent
local memory
memory="$(build_memory "$agent")"
# Remplacer memories: [] par le bloc injecté
# Utilise awk pour éviter les conflits avec les caractères spéciaux (|, <, >) dans sed
awk -v mem="$memory" '
/^memories: \[\]/ { print "memories:"; print " - \"" mem "\""; next }
{ print }
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
echo " [ok] $agent — memory injectée"
else
echo " [warn] $agent — format memories: inattendu, patch manuel requis"
fi
}
build_memory() {
local agent="$1"
local base="When a reusable pattern, difficult bug fix, anti-pattern, or architecture decision emerges"
case "$agent" in
bmm-dev|bmm-quick-flow-solo-dev)
echo "${base} during implementation, write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md (NUC: /srv/projects/_Assistant_Lead_Tech/95_a_capitaliser.md). Format: DATE — ${PROJECT_NAME} / FILE_UPDATE_PROPOSAL / Fichier cible: <10_backend_patterns_valides.md | 10_frontend_patterns_valides.md | 10_backend_risques_et_vigilance.md | 10_frontend_risques_et_vigilance.md | 90_debug_et_postmortem.md> / Pourquoi: <reason> / Proposition: <content>. Never write directly to Lead_tech validated files."
;;
bmm-architect)
echo "${base} during architecture or technical design, write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md (NUC: /srv/projects/_Assistant_Lead_Tech/95_a_capitaliser.md). Format: DATE — ${PROJECT_NAME} / FILE_UPDATE_PROPOSAL / Fichier cible: <40_decisions_et_archi.md | 10_backend_patterns_valides.md | 10_backend_risques_et_vigilance.md> / Pourquoi: <reason> / Proposition: <content>. Never write directly to Lead_tech validated files."
;;
bmm-sm)
echo "When a process improvement, recurring friction, or architecture decision emerges during sprint work, write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md (NUC: /srv/projects/_Assistant_Lead_Tech/95_a_capitaliser.md). Format: DATE — ${PROJECT_NAME} / FILE_UPDATE_PROPOSAL / Fichier cible: <target file> / Pourquoi: <reason> / Proposition: <content>. Never write directly to Lead_tech validated files."
;;
bmm-qa|tea-tea)
echo "When a reusable test pattern, tricky bug, or quality anti-pattern is identified, write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md (NUC: /srv/projects/_Assistant_Lead_Tech/95_a_capitaliser.md). Format: DATE — ${PROJECT_NAME} / FILE_UPDATE_PROPOSAL / Fichier cible: <target file> / Pourquoi: <reason> / Proposition: <content>. Never write directly to Lead_tech validated files."
;;
bmm-analyst)
echo "When a reusable analysis pattern, requirements anti-pattern, or domain insight emerges, write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md (NUC: /srv/projects/_Assistant_Lead_Tech/95_a_capitaliser.md). Format: DATE — ${PROJECT_NAME} / FILE_UPDATE_PROPOSAL / Fichier cible: <10_product_patterns_valides.md | 10_backend_patterns_valides.md | 40_decisions_et_archi.md> / Pourquoi: <reason> / Proposition: <content>. Never write directly to Lead_tech validated files."
;;
bmm-pm)
echo "When a product decision, prioritization pattern, or recurring friction is identified, write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md (NUC: /srv/projects/_Assistant_Lead_Tech/95_a_capitaliser.md). Format: DATE — ${PROJECT_NAME} / FILE_UPDATE_PROPOSAL / Fichier cible: <10_product_patterns_valides.md | 40_decisions_et_archi.md> / Pourquoi: <reason> / Proposition: <content>. Never write directly to Lead_tech validated files."
;;
bmm-ux-designer)
echo "When a reusable UX/UI pattern, interaction anti-pattern, or UX decision emerges, write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md (NUC: /srv/projects/_Assistant_Lead_Tech/95_a_capitaliser.md). Format: DATE — ${PROJECT_NAME} / FILE_UPDATE_PROPOSAL / Fichier cible: <10_ux_patterns_valides.md | 10_ux_risques_et_vigilance.md | 40_decisions_et_archi.md> / Pourquoi: <reason> / Proposition: <content>. Never write directly to Lead_tech validated files."
;;
bmm-tech-writer)
echo "When a reusable documentation pattern, writing convention, or recurring documentation friction emerges, write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md (NUC: /srv/projects/_Assistant_Lead_Tech/95_a_capitaliser.md). Format: DATE — ${PROJECT_NAME} / FILE_UPDATE_PROPOSAL / Fichier cible: <10_conventions_redaction.md | 40_decisions_et_archi.md> / Pourquoi: <reason> / Proposition: <content>. Never write directly to Lead_tech validated files."
;;
core-bmad-master)
echo "As the orchestrating agent, when any cross-cutting pattern, process improvement, recurring friction, or architectural decision emerges across the project, write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md (NUC: /srv/projects/_Assistant_Lead_Tech/95_a_capitaliser.md). Format: DATE — ${PROJECT_NAME} / FILE_UPDATE_PROPOSAL / Fichier cible: <10_backend_patterns_valides.md | 10_frontend_patterns_valides.md | 10_product_patterns_valides.md | 10_ux_patterns_valides.md | 10_backend_risques_et_vigilance.md | 10_frontend_risques_et_vigilance.md | 40_decisions_et_archi.md | 90_debug_et_postmortem.md> / Pourquoi: <reason> / Proposition: <content>. Never write directly to Lead_tech validated files."
;;
esac
}
CAPITALIZE_MARKER_XML="Capitalisation Lead_tech"
DEV_STORY_XML="$PROJECT_ROOT/_bmad/bmm/workflows/4-implementation/dev-story/instructions.xml"
CODE_REVIEW_XML="$PROJECT_ROOT/_bmad/bmm/workflows/4-implementation/code-review/instructions.xml"
DEV_STORY_CHECKLIST="$PROJECT_ROOT/_bmad/bmm/workflows/4-implementation/dev-story/checklist.md"
CODE_REVIEW_CHECKLIST="$PROJECT_ROOT/_bmad/bmm/workflows/4-implementation/code-review/checklist.md"
patch_dev_story() {
local file="$DEV_STORY_XML"
PRODUCER_AGENTS_CONFIG="$TEMPLATES_DIR/config/producer_agents.tsv"
MEMORIES_DIR="$TEMPLATES_DIR/memories"
WORKFLOWS_DIR="$TEMPLATES_DIR/workflows"
CLAUDE_FRAGMENTS_DIR="$TEMPLATES_DIR/claude"
CAPITALIZE_MARKER="95_a_capitaliser.md"
CAPITALIZE_MARKER_XML="Capitalisation Lead_tech"
if [ ! -d "$AGENTS_DIR" ]; then
echo "Erreur : dossier _bmad/_config/agents/ introuvable dans $PROJECT_ROOT" >&2
echo "Lance ce script depuis la racine d'un projet BMAD installé." >&2
exit 1
fi
require_file() {
local file="$1"
if [ ! -f "$file" ]; then
echo "Erreur : fichier requis introuvable : $file" >&2
exit 1
fi
}
escape_sed_replacement() {
printf '%s' "$1" | sed -e 's/[\/&]/\\&/g'
}
render_template() {
local file="$1"
require_file "$file"
sed "s/__PROJECT_NAME__/$(escape_sed_replacement "$PROJECT_NAME")/g" "$file"
}
patch_line_after_match() {
local file="$1"
local match="$2"
local fragment_file="$3"
if [ ! -f "$file" ]; then
echo " [skip] dev-story/instructions.xml — fichier absent"
echo " [skip] $(basename "$file") — fichier absent"
return 0
fi
if grep -q "$CAPITALIZE_MARKER_XML" "$file"; then
echo " [skip] dev-story/instructions.xml — capitalisation déjà présente"
echo " [skip] $(basename "$file") — capitalisation déjà présente"
return 0
fi
# Insérer le bloc capitalisation juste avant les Final validation gates
awk '
/<!-- Final validation gates -->/ {
print " <!-- Capitalisation Lead_tech -->"
print " <critical>You MUST output this section \xe2\x80\x94 do NOT skip it silently</critical>"
print " <output>## \xf0\x9f\xa7\xa0 Capitalisation Lead_tech"
print ""
print " Review the full implementation for: reusable patterns, difficult bug fixes, anti-patterns, architecture decisions, or subtle nuances discovered during this story."
print " </output>"
print " <action>For EACH candidate (aim for 1-3): write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md ONLY \xe2\x80\x94 NEVER inside the project repo. FORMAT = \"DATE \xe2\x80\x94 '"$PROJECT_NAME"' / FILE_UPDATE_PROPOSAL / Fichier cible: &lt;target&gt; / Pourquoi: &lt;reason&gt; / Proposition: &lt;content&gt;\"</action>"
print " <action if=\"nothing worth capitalizing\">Output explicitly: \"Rien \xc3\xa0 capitaliser pour cette story.\" \xe2\x80\x94 do NOT skip silently</action>"
print ""
local fragment
fragment="$(render_template "$fragment_file")"
awk -v match="$match" -v block="$fragment" '
index($0, match) {
print
print block
next
}
{ print }
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
echo " [ok] dev-story/instructions.xml — capitalisation injectée"
echo " [ok] $(basename "$file") — capitalisation injectée"
}
patch_code_review() {
local file="$CODE_REVIEW_XML"
patch_block_before_match() {
local file="$1"
local match="$2"
local fragment_file="$3"
if [ ! -f "$file" ]; then
echo " [skip] code-review/instructions.xml — fichier absent"
echo " [skip] $(basename "$file") — fichier absent"
return 0
fi
if grep -q "$CAPITALIZE_MARKER_XML" "$file"; then
echo " [skip] code-review/instructions.xml — capitalisation déjà présente"
echo " [skip] $(basename "$file") — capitalisation déjà présente"
return 0
fi
# Insérer le bloc capitalisation après le output "✅ Review Complete!"
awk '
local fragment
fragment="$(render_template "$fragment_file")"
awk -v match="$match" -v block="$fragment" '
index($0, match) {
print block
}
{ print }
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
echo " [ok] $(basename "$file") — capitalisation injectée"
}
patch_agent() {
local agent="$1"
local template_name="$2"
local file="$AGENTS_DIR/${agent}.customize.yaml"
local template_file="$MEMORIES_DIR/${template_name}.txt"
if [ ! -f "$file" ]; then
return 0
fi
require_file "$template_file"
if grep -q "$CAPITALIZE_MARKER" "$file"; then
echo " [skip] $agent — memory déjà présente"
return 0
fi
if ! grep -q "^memories: \[\]" "$file"; then
echo " [warn] $agent — format memories: inattendu, patch manuel requis"
return 0
fi
local memory
memory="$(render_template "$template_file")"
awk -v mem="$memory" '
/^memories: \[\]/ { print "memories:"; print " - \"" mem "\""; next }
{ print }
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
echo " [ok] $agent — memory injectée"
}
patch_agents() {
require_file "$PRODUCER_AGENTS_CONFIG"
while IFS=$'\t' read -r agent template_name; do
if [ -z "${agent:-}" ] || [ "${agent#\#}" != "$agent" ]; then
continue
fi
patch_agent "$agent" "$template_name"
done < "$PRODUCER_AGENTS_CONFIG"
}
patch_dev_story() {
patch_block_before_match \
"$DEV_STORY_XML" \
"<!-- Final validation gates -->" \
"$WORKFLOWS_DIR/dev-story-capitalisation.xmlfrag"
}
patch_code_review() {
local file="$CODE_REVIEW_XML"
local fragment_file="$WORKFLOWS_DIR/code-review-capitalisation.xmlfrag"
if [ ! -f "$file" ]; then
echo " [skip] $(basename "$file") — fichier absent"
return 0
fi
if grep -q "$CAPITALIZE_MARKER_XML" "$file"; then
echo " [skip] $(basename "$file") — capitalisation déjà présente"
return 0
fi
local fragment
fragment="$(render_template "$fragment_file")"
awk -v block="$fragment" '
/✅ Review Complete!/ { in_review_complete = 1 }
in_review_complete && /<\/output>/ {
print
print ""
print " <!-- Capitalisation Lead_tech -->"
print " <critical>You MUST output this section \xe2\x80\x94 do NOT skip it silently</critical>"
print " <output>## \xf0\x9f\xa7\xa0 Capitalisation Lead_tech"
print ""
print " Review all findings for: anti-patterns found, recurring issues, architecture decisions confirmed or invalidated during this review."
print " </output>"
print " <action>For EACH candidate (aim for 1-3): write a proposal to ~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md ONLY \xe2\x80\x94 NEVER inside the project repo. FORMAT = \"DATE \xe2\x80\x94 '"$PROJECT_NAME"' / FILE_UPDATE_PROPOSAL / Fichier cible: &lt;target&gt; / Pourquoi: &lt;reason&gt; / Proposition: &lt;content&gt;\"</action>"
print " <action if=\"nothing worth capitalizing\">Output explicitly: \"Rien \xc3\xa0 capitaliser pour cette review.\" \xe2\x80\x94 do NOT skip silently</action>"
print block
in_review_complete = 0
next
}
{ print }
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
echo " [ok] code-review/instructions.xml — capitalisation injectée"
echo " [ok] $(basename "$file") — capitalisation injectée"
}
patch_dev_story_checklist() {
local file="$DEV_STORY_CHECKLIST"
if [ ! -f "$file" ]; then
echo " [skip] dev-story/checklist.md — fichier absent"
return 0
fi
if grep -q "$CAPITALIZE_MARKER_XML" "$file"; then
echo " [skip] dev-story/checklist.md — capitalisation déjà présente"
return 0
fi
awk '
/\*\*User Communication Ready\*\*/ {
print
print "- [ ] **Capitalisation Lead_tech:** Section \"🧠 Capitalisation Lead_tech\" outputted — proposals written to \`95_a_capitaliser.md\` OR explicit \"Rien à capitaliser\" stated"
next
}
{ print }
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
echo " [ok] dev-story/checklist.md — capitalisation injectée"
patch_line_after_match \
"$DEV_STORY_CHECKLIST" \
"**User Communication Ready**" \
"$WORKFLOWS_DIR/dev-story-checklist.mdfrag"
}
patch_code_review_checklist() {
local file="$CODE_REVIEW_CHECKLIST"
if [ ! -f "$file" ]; then
echo " [skip] code-review/checklist.md — fichier absent"
return 0
fi
if grep -q "$CAPITALIZE_MARKER_XML" "$file"; then
echo " [skip] code-review/checklist.md — capitalisation déjà présente"
return 0
fi
awk '
/Story saved successfully/ {
print
print "- [ ] Capitalisation Lead_tech outputted — proposals written to \`95_a_capitaliser.md\` OR explicit \"Rien à capitaliser\" stated"
next
}
{ print }
' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
echo " [ok] code-review/checklist.md — capitalisation injectée"
patch_line_after_match \
"$CODE_REVIEW_CHECKLIST" \
"Story saved successfully" \
"$WORKFLOWS_DIR/code-review-checklist.mdfrag"
}
patch_claude_md() {
local fragment_file="$CLAUDE_FRAGMENTS_DIR/leadtech-capitalisation.mdfrag"
if [ ! -f "$CLAUDE_MD" ]; then
echo " [skip] CLAUDE.md — fichier absent"
return 0
@@ -250,39 +218,7 @@ patch_claude_md() {
return 0
fi
cat >> "$CLAUDE_MD" <<EOF
---
# Capitalisation vers Lead_tech
Quand un apprentissage émerge (bug difficile, pattern réutilisable, anti-pattern, décision d'archi),
l'écrire dans la zone tampon Lead_tech :
\`\`\`
~/AI_RULES/_Assistant_Lead_Tech/95_a_capitaliser.md
\`\`\`
Sur le NUC : \`/srv/projects/_Assistant_Lead_Tech/95_a_capitaliser.md\`
Format :
\`\`\`
DATE — ${PROJECT_NAME}
FILE_UPDATE_PROPOSAL
Fichier cible : <10_backend_patterns_valides.md | 10_frontend_patterns_valides.md | 10_ux_patterns_valides.md | 10_backend_risques_et_vigilance.md | 10_frontend_risques_et_vigilance.md | 10_ux_risques_et_vigilance.md | 40_decisions_et_archi.md | 90_debug_et_postmortem.md>
Pourquoi :
<raison en 1-2 phrases>
Proposition :
<contenu suggéré>
\`\`\`
Règle : écrire dans \`95_a_capitaliser.md\` uniquement. Jamais directement dans les fichiers Lead_tech validés.
EOF
render_template "$fragment_file" >> "$CLAUDE_MD"
echo " [ok] CLAUDE.md — section capitalisation ajoutée"
}
@@ -291,12 +227,11 @@ echo ""
echo "post-bmad-install — injection Lead_tech capitalisation"
echo "Projet : $PROJECT_NAME ($PROJECT_ROOT)"
echo "Agents : $AGENTS_DIR"
echo "Templates : $TEMPLATES_DIR"
echo ""
echo "Patch agents :"
for agent in "${PRODUCER_AGENTS[@]}"; do
patch_agent "$agent"
done
patch_agents
echo ""
echo "Patch workflows :"