Synthèse
Script Bash pour Neovim permettant l'intégration d'un assistant IA (Claude) capable de détecter intelligemment le type d'action demandée (remplacement, insertion, amélioration ou affichage) en analysant les instructions de l'utilisateur. Le script lit les fichiers CLAUDE.md globaux et locaux pour appliquer les règles spécifiques du projet lors du traitement des requêtes d'édition de texte.
Create ~/. config/nvim/scripts/kai-neovim. sh: bash#! /bin/bash # Kai Neovim Enhancement Script with Intelligent Action Detection # Usage: kai-neovim. sh CONTEXT_FILE="$1" PROMPT="$2" # Check if claude CLI is available (we use it to communicate with Kai) if !
command -v claude &> /dev/null; then echo "Error: Claude CLI not found. Please install it first. " exit 1 fi # Read the CLAUDE. md files for additional context (project-specific rules for Kai) GLOBAL_CLAUDE_MD="" LOCAL_CLAUDE_MD="" if [ -f "$HOME/. claude/CLAUDE.
md" ]; then GLOBAL_CLAUDE_MD=$(cat "$HOME/. claude/CLAUDE. md") fi # Find the nearest CLAUDE. md in the project CURRENT_DIR=$(pwd) while [ "$CURRENT_DIR" ! = "/" ]; do if [ -f "$CURRENT_DIR/CLAUDE.
md" ]; then LOCAL_CLAUDE_MD=$(cat "$CURRENT_DIR/CLAUDE. md") break fi CURRENT_DIR=$(dirname "$CURRENT_DIR") done # Regular text enhancement request - let Kai determine the action FULL_PROMPT="You are Kai, an AI assistant integrated into Neovim. CRITICAL CONTEXT FROM CLAUDE. md FILES (FOLLOW THESE RULES EXACTLY): ================================================== GLOBAL CLAUDE. md: $GLOBAL_CLAUDE_MD PROJECT CLAUDE.
md: $LOCAL_CLAUDE_MD ================================================== CURRENT EDITING CONTEXT: $(cat "$CONTEXT_FILE") CRITICAL: INTELLIGENT ACTION DETECTION You must analyze the user's instruction to determine what they want: 1. If they say things like \"replace with\", \"change to\", \"rewrite as\", \"make this\", \"convert to\" → REPLACE the selected text 2. If they say things like \"write something like this\", \"create a note about\", \"add after\", \"insert\" → INSERT new content (don't replace) 3. If they say things like \"improve\", \"enhance\", \"fix\", \"correct\" → REPLACE with improved version 4.