From 0213e23c87f71baaa01a41f4f41d2f7e3f43895d Mon Sep 17 00:00:00 2001 From: HarakaraSite Date: Wed, 11 Feb 2026 22:11:14 +0900 Subject: [PATCH] commit 7 --- script/fix_and_explain_strudel.sh | 22 +++++++++++++--------- script/refactor_strudel.sh | 23 ++++++++++++++--------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/script/fix_and_explain_strudel.sh b/script/fix_and_explain_strudel.sh index 94c739a..80b31a4 100644 --- a/script/fix_and_explain_strudel.sh +++ b/script/fix_and_explain_strudel.sh @@ -6,6 +6,11 @@ OUTPUT_DIR="$BASE_DIR/explained" SKILL_FILE="$BASE_DIR/.gemini/skills/strudel_fix_and_explain.md" # 出力先フォルダの作成 +if [ ! -f "$SKILL_FILE" ]; then + echo "Error: Skill file not found at $SKILL_FILE" + exit 1 +fi + mkdir -p "$OUTPUT_DIR" # 引数がある場合はそれを使用し、ない場合は strudel/ フォルダの全mdファイルを対象にする @@ -19,14 +24,13 @@ echo "Strudel Fix & Explain Skill started..." for file in "${files[@]}"; do # 除外設定 - [[ "$file" == *"Strudel Making Sound.md"* ]] && continue - [[ "$file" == *"Strudel Study.md"* ]] && continue - [[ "$file" == *"/refactoring/"* ]] && continue - [[ "$file" == *"/explained/"* ]] && continue - [[ "$file" == *"/script/"* ]] && continue [ -f "$file" ] || continue filename=$(basename "$file") + # 特定のファイルやディレクトリを除外 + [[ "$filename" =~ ^(Strudel Making Sound|Strudel Study)\.md$ ]] && continue + [[ "$file" =~ /(refactoring|script|explained|organized_strudel)/ ]] && continue + echo "Analyzing and fixing $filename..." # 一時ファイルに出力 @@ -34,12 +38,12 @@ for file in "${files[@]}"; do (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') + # FILENAME: タグを検索 + suggested_name=$(grep -m 1 "FILENAME:" "$tmp_file" | sed 's/FILENAME: //g' | tr -d '\r') if [ -n "$suggested_name" ]; then - # 1行目を除去して保存 - tail -n +2 "$tmp_file" > "$OUTPUT_DIR/$suggested_name" + # FILENAME行を除去して保存 + sed '/FILENAME:/d' "$tmp_file" > "$OUTPUT_DIR/$suggested_name" rm "$tmp_file" echo "Done: $OUTPUT_DIR/$suggested_name" else diff --git a/script/refactor_strudel.sh b/script/refactor_strudel.sh index 71f0d98..c6a0577 100644 --- a/script/refactor_strudel.sh +++ b/script/refactor_strudel.sh @@ -6,6 +6,11 @@ REFACTOR_DIR="$BASE_DIR/refactoring" SKILL_FILE="$BASE_DIR/.gemini/skills/strudel_refactor.md" # 出力先フォルダの作成 +if [ ! -f "$SKILL_FILE" ]; then + echo "Error: Skill file not found at $SKILL_FILE" + exit 1 +fi + mkdir -p "$REFACTOR_DIR" # 引数がある場合はそれを使用し、ない場合は strudel/ フォルダの全mdファイルを対象にする @@ -19,13 +24,13 @@ 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") + # 特定のファイルやディレクトリを除外 + [[ "$filename" =~ ^(Strudel Making Sound|Strudel Study)\.md$ ]] && continue + [[ "$file" =~ /(refactoring|script|explained|organized_strudel)/ ]] && continue + echo "Processing $filename..." # スキルファイルをシステムプロンプトとして使用 @@ -33,12 +38,12 @@ for file in "${files[@]}"; do (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') + # 最初の数行から FILENAME: タグを検索(より柔軟な抽出) + suggested_name=$(grep -m 1 "FILENAME:" "$tmp_file" | sed 's/FILENAME: //g' | tr -d '\r') if [ -n "$suggested_name" ]; then - # 1行目(FILENAME行)を除去してリネーム保存 - tail -n +2 "$tmp_file" > "$REFACTOR_DIR/$suggested_name" + # FILENAME行を除去して保存 (最初の1行目にあると仮定しつつ、sedで安全に削除) + sed '/FILENAME:/d' "$tmp_file" > "$REFACTOR_DIR/$suggested_name" rm "$tmp_file" echo "Successfully refactored and renamed to: $suggested_name" else