Files
brain-template/scripts/kernel-isolation-check.sh
Tetardtek 878886cd51 feat: brain-template v2.0 — BSI-v3 complet + tiers documentés
- README reécrit : tiers free/pro/full + modèle clé API + multi-instance
- Sync agents/ (57 agents, kernel-isolation validated)
- Sync scripts/ BSI-v3 (file-lock, preflight, human-gate, brain-status)
- KERNEL.md v0.7.0 — zones + délégation + rendering + isolation
- brain-compose.yml v0.7.0 — rendering mode + kerneluser
- workflows/ — template + brain-engine exemple
- locks/.gitkeep + claims/.gitkeep
- helloWorld : RAG boot tier full only (bsi-rag retiré du template)
2026-03-16 23:26:38 +01:00

126 lines
4.2 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# kernel-isolation-check.sh — Firewall toolkit/private
# Vérifie qu'aucun agent kernel ne contient de dépendances dures vers des fichiers privés.
#
# WARN : référence documentaire (normal — l'agent décrit l'architecture)
# ERROR : dépendance dure (problème — l'agent ne peut pas fonctionner sans le fichier privé)
#
# Usage : bash scripts/kernel-isolation-check.sh [--strict]
# --strict : traite les WARN comme des ERROR
set -euo pipefail
BRAIN_ROOT="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)"
AGENTS_DIR="$BRAIN_ROOT/agents"
STRICT=${1:-""}
ERRORS=()
WARNS=()
# --- Patterns ERROR : dépendances dures — jamais dans un agent distributable ---
# Chemin absolu machine, requires:, load:, source: vers privé
ERROR_PATTERNS=(
"toolkit/private/"
"require.*toolkit/private"
"load.*MYSECRETS"
"source.*MYSECRETS"
)
# Patterns de chemin absolu — exclusions pour les placeholders templates
ABSOLUTE_PATH_PATTERN="/home/[a-z]" # /home/tetardtek — chemin réel, pas /home/<user>
ABSOLUTE_PATH_EXCLUDE="<" # Exclure les lignes avec placeholder (<user>, <PATHS...)
# --- Patterns WARN : références documentaires — OK si contexte architecture ---
# L'agent mentionne le concept mais n'en dépend pas fonctionnellement
WARN_PATTERNS=(
"MYSECRETS"
"brain-compose.local"
"profil/capital"
"profil/objectifs"
"progression/"
)
echo "🔍 Kernel isolation check — agents/ → dépendances privées"
echo ""
# --- Scan ERROR — patterns interdits ---
for pattern in "${ERROR_PATTERNS[@]}"; do
matches=$(grep -rl "$pattern" "$AGENTS_DIR" \
--include="*.md" \
--exclude-dir=reviews \
2>/dev/null || true)
if [ -n "$matches" ]; then
while IFS= read -r file; do
rel="${file#$BRAIN_ROOT/}"
line=$(grep -n "$pattern" "$file" | head -1 | cut -d: -f1)
ERRORS+=(" 🚨 ERROR $rel:$line → dépendance dure \"$pattern\"")
done <<< "$matches"
fi
done
# --- Scan ERROR — chemins absolus réels (ex: /home/tetardtek/, pas /home/<user>/) ---
while IFS= read -r -d '' file; do
# Cherche /home/[a-z] et exclut les lignes avec placeholder <
matches=$(grep -n "$ABSOLUTE_PATH_PATTERN" "$file" 2>/dev/null \
| grep -v "$ABSOLUTE_PATH_EXCLUDE" || true)
if [ -n "$matches" ]; then
rel="${file#$BRAIN_ROOT/}"
line=$(echo "$matches" | head -1 | cut -d: -f1)
ERRORS+=(" 🚨 ERROR $rel:$line → chemin machine absolu hardcodé")
fi
done < <(find "$AGENTS_DIR" -name "*.md" \
-not -path "*/reviews/*" \
-not -path "*/_template*" \
| tr '\n' '\0')
# --- Scan WARN ---
for pattern in "${WARN_PATTERNS[@]}"; do
matches=$(grep -rl "$pattern" "$AGENTS_DIR" \
--include="*.md" \
--exclude-dir=reviews \
2>/dev/null || true)
if [ -n "$matches" ]; then
while IFS= read -r file; do
rel="${file#$BRAIN_ROOT/}"
line=$(grep -n "$pattern" "$file" | head -1 | cut -d: -f1)
WARNS+=(" ⚠️ WARN $rel:$line → référence doc \"$pattern\"")
done <<< "$matches"
fi
done
# --- Rapport ---
if [ ${#ERRORS[@]} -gt 0 ]; then
echo "🚨 ERREURS — dépendances dures détectées (kernel NON distribuable) :"
echo ""
for e in "${ERRORS[@]}"; do echo "$e"; done
echo ""
fi
if [ ${#WARNS[@]} -gt 0 ]; then
echo "⚠️ AVERTISSEMENTS — références documentaires (attendu, pas bloquant) :"
echo ""
for w in "${WARNS[@]}"; do echo "$w"; done
echo ""
echo " Ces références décrivent l'architecture brain — elles n'empêchent pas la distribution."
echo " Un utilisateur qui forke aura ses propres fichiers à ces chemins."
echo ""
fi
# --- Résultat ---
if [ ${#ERRORS[@]} -eq 0 ] && [ "$STRICT" != "--strict" ]; then
echo "✅ Kernel isolation OK — aucune dépendance dure privée détectée"
echo " ${#WARNS[@]} références documentaires (normales)"
exit 0
elif [ ${#ERRORS[@]} -eq 0 ] && [ "$STRICT" = "--strict" ] && [ ${#WARNS[@]} -eq 0 ]; then
echo "✅ Kernel isolation OK (strict) — zéro violation"
exit 0
elif [ "$STRICT" = "--strict" ] && [ ${#WARNS[@]} -gt 0 ]; then
echo "🚨 Mode strict — ${#WARNS[@]} WARN traités comme ERROR"
exit 1
else
echo "🚨 ${#ERRORS[@]} erreur(s) bloquante(s) — corriger avant distribution"
exit 1
fi