mirror of
https://github.com/MaksTinyWorkshop/_Assistant_Lead_Tech
synced 2026-04-06 21:41:42 +02:00
move scripts + create mkproj
This commit is contained in:
105
scripts/sync-ai-instructions.sh
Executable file
105
scripts/sync-ai-instructions.sh
Executable file
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env bash
|
||||
# sync-ai-instructions.sh
|
||||
# Génère un unique CLAUDE.md dans le repo Lead_tech depuis _AI_INSTRUCTIONS.md + _projects.conf
|
||||
# puis recrée les liens symboliques nécessaires vers ce fichier unique
|
||||
# selon la machine courante (Darwin = Mac, Linux = NUC)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
SOURCE="$REPO_ROOT/_AI_INSTRUCTIONS.md"
|
||||
PROJECTS_CONF="$REPO_ROOT/_projects.conf"
|
||||
|
||||
# --- Détection machine ---
|
||||
OS="$(uname -s)"
|
||||
CHANGED=0
|
||||
|
||||
# --- Construire la table markdown des projets ---
|
||||
build_projects_table() {
|
||||
local os="$1"
|
||||
echo "| Projet | Stack | Localisation | État |"
|
||||
echo "|---|---|---|---|"
|
||||
while IFS='|' read -r nom stack path_nuc path_mac etat; do
|
||||
# Ignorer lignes vides et commentaires
|
||||
[[ -z "$nom" || "$nom" == \#* ]] && continue
|
||||
if [ "$os" = "Darwin" ]; then
|
||||
path="$path_mac"
|
||||
else
|
||||
path="$path_nuc"
|
||||
fi
|
||||
if [ -z "$path" ]; then
|
||||
echo "| $nom | $stack | *non disponible sur cette machine* | $etat |"
|
||||
else
|
||||
echo "| $nom | $stack | \`$path\` | $etat |"
|
||||
fi
|
||||
done < "$PROJECTS_CONF"
|
||||
}
|
||||
|
||||
generate_repo_claude() {
|
||||
local header="$1"
|
||||
local dest="$2"
|
||||
local projects_table
|
||||
local tmp
|
||||
projects_table="$(build_projects_table "$OS")"
|
||||
tmp="$(mktemp)"
|
||||
|
||||
mkdir -p "$(dirname "$dest")"
|
||||
|
||||
{
|
||||
echo "$header"
|
||||
echo ""
|
||||
# Remplacer {{PROJECTS_TABLE}} par la table générée
|
||||
while IFS= read -r line; do
|
||||
if [ "$line" = "{{PROJECTS_TABLE}}" ]; then
|
||||
echo "$projects_table"
|
||||
else
|
||||
echo "$line"
|
||||
fi
|
||||
done < "$SOURCE"
|
||||
} > "$tmp"
|
||||
|
||||
if [ ! -f "$dest" ] || ! cmp -s "$tmp" "$dest"; then
|
||||
mv "$tmp" "$dest"
|
||||
CHANGED=1
|
||||
else
|
||||
rm -f "$tmp"
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_symlink() {
|
||||
local target="$1"
|
||||
local link_path="$2"
|
||||
|
||||
mkdir -p "$(dirname "$link_path")"
|
||||
|
||||
if [ -L "$link_path" ]; then
|
||||
local current_target
|
||||
current_target="$(readlink "$link_path")"
|
||||
if [ "$current_target" = "$target" ]; then
|
||||
return 0
|
||||
fi
|
||||
elif [ -e "$link_path" ]; then
|
||||
rm -f "$link_path"
|
||||
fi
|
||||
|
||||
rm -f "$link_path"
|
||||
ln -s "$target" "$link_path"
|
||||
CHANGED=1
|
||||
}
|
||||
|
||||
CLAUDE_HEADER="# Instructions globales — Lead Tech Copilote
|
||||
|
||||
Ce fichier est chargé automatiquement par Claude Code ou Codex à chaque session.
|
||||
Il constitue la porte d'entrée principale de la base de connaissance Lead_tech et oriente vers les fichiers spécialisés utilisés par tous les projets."
|
||||
|
||||
generate_repo_claude "$CLAUDE_HEADER" "$REPO_ROOT/CLAUDE.md"
|
||||
|
||||
ensure_symlink "$REPO_ROOT/CLAUDE.md" "$HOME/.claude/CLAUDE.md"
|
||||
ensure_symlink "$HOME/.claude/CLAUDE.md" "$HOME/.codex/AGENTS.md"
|
||||
ensure_symlink "$REPO_ROOT/CLAUDE.md" "$REPO_ROOT/AGENTS.md"
|
||||
|
||||
if [ "$CHANGED" -eq 1 ]; then
|
||||
echo "Sync AI instructions (OS: $OS)"
|
||||
echo "Sync terminée."
|
||||
fi
|
||||
Reference in New Issue
Block a user