#!/bin/bash # スクリプトの場所 (scripts/) からプロジェクトルート (notebook/) を動的に取得 BASE_DIR=$(cd "$(dirname "$0")/.." && pwd) REFACTOR_DIR="$BASE_DIR/refactoring" SKILL_FILE="$BASE_DIR/.gemini/skills/strudel_refactor.md" # 出力先フォルダの作成 mkdir -p "$REFACTOR_DIR" # 引数がある場合はそれを使用し、ない場合は strudel/ フォルダの全mdファイルを対象にする if [ $# -gt 0 ]; then files=("$@") else files=("$BASE_DIR/strudel"/*.md) fi echo "Strudel Code Analysis & Refactoring Skill started..." for file in "${files[@]}"; do # 除外設定 [[ "$file" == *"Strudel Making Sound.md"* ]] && continue [[ "$file" == *"Strudel Study.md"* ]] && continue [[ "$file" == *"/refactoring/"* ]] && continue [[ "$file" == *"/script/"* ]] && continue [ -f "$file" ] || continue filename=$(basename "$file") echo "Processing $filename..." # スキルファイルをシステムプロンプトとして使用 tmp_file="$REFACTOR_DIR/tmp_$filename" (cat "$SKILL_FILE"; echo ""; cat "$file") | gemini > "$tmp_file" if [ $? -eq 0 ]; then # 1行目から提案されたファイル名を抽出 suggested_name=$(head -n 1 "$tmp_file" | grep "FILENAME:" | sed 's/FILENAME: //g' | tr -d '\r') if [ -n "$suggested_name" ]; then # 1行目(FILENAME行)を除去してリネーム保存 tail -n +2 "$tmp_file" > "$REFACTOR_DIR/$suggested_name" rm "$tmp_file" echo "Successfully refactored and renamed to: $suggested_name" else mv "$tmp_file" "$REFACTOR_DIR/$filename" echo "Successfully refactored: $filename (Rename tag not found)" fi else rm -f "$tmp_file" echo "Error processing $filename" fi done