add
This commit is contained in:
184
scripts/ai-integration.sh
Executable file
184
scripts/ai-integration.sh
Executable file
@ -0,0 +1,184 @@
|
||||
#!/bin/bash
|
||||
# AI統合ヘルパースクリプト
|
||||
|
||||
# カラー定義
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
# 設定
|
||||
CLAUDE_LOG_DIR="$HOME/claude-logs"
|
||||
CHATGPT_LOG_DIR="$HOME/chatgpt-logs"
|
||||
AI_CONTEXT_DIR="$HOME/.ai-context"
|
||||
|
||||
# ディレクトリ作成
|
||||
mkdir -p "$CLAUDE_LOG_DIR" "$CHATGPT_LOG_DIR" "$AI_CONTEXT_DIR"
|
||||
|
||||
# ChatGPTの会話をClaude Codeにインポート
|
||||
import_chatgpt_conversation() {
|
||||
local chatgpt_file="$1"
|
||||
local context_name="${2:-imported-context}"
|
||||
|
||||
if [[ ! -f "$chatgpt_file" ]]; then
|
||||
echo -e "${YELLOW}ファイルが見つかりません: $chatgpt_file${NC}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# コンテキストファイルを作成
|
||||
cat > "$AI_CONTEXT_DIR/$context_name.md" << EOF
|
||||
# インポートされたChatGPT会話
|
||||
インポート日時: $(date)
|
||||
ソースファイル: $chatgpt_file
|
||||
|
||||
## 会話内容
|
||||
$(cat "$chatgpt_file")
|
||||
|
||||
## Claude Codeへの指示
|
||||
この会話の内容を踏まえて、以下の点に注意して作業を進めてください:
|
||||
1. ChatGPTで議論された設計方針を尊重する
|
||||
2. 未解決の課題があれば解決する
|
||||
3. 実装の詳細を具体化する
|
||||
EOF
|
||||
|
||||
echo -e "${GREEN}✓ ChatGPT会話をインポートしました: $AI_CONTEXT_DIR/$context_name.md${NC}"
|
||||
|
||||
# Claude Codeを起動
|
||||
claude "以下のChatGPTとの会話を確認して、実装を進めてください: @$AI_CONTEXT_DIR/$context_name.md"
|
||||
}
|
||||
|
||||
# 複数AIで同じタスクを実行して比較
|
||||
multi_ai_task() {
|
||||
local task="$1"
|
||||
local output_dir="$AI_CONTEXT_DIR/comparisons/$(date +%Y%m%d-%H%M%S)"
|
||||
mkdir -p "$output_dir"
|
||||
|
||||
echo -e "${BLUE}複数AIでタスクを実行中...${NC}"
|
||||
|
||||
# Claude Code
|
||||
echo -e "${GREEN}Claude Code:${NC}"
|
||||
claude "$task" > "$output_dir/claude_response.md" 2>&1
|
||||
|
||||
# 他のAI(例:ollama)
|
||||
if command -v ollama &> /dev/null; then
|
||||
echo -e "${GREEN}Ollama (llama2):${NC}"
|
||||
echo "$task" | ollama run llama2 > "$output_dir/ollama_response.md" 2>&1
|
||||
fi
|
||||
|
||||
# 結果を統合
|
||||
cat > "$output_dir/comparison.md" << EOF
|
||||
# AI比較結果
|
||||
タスク: $task
|
||||
実行日時: $(date)
|
||||
|
||||
## Claude Code
|
||||
\`\`\`
|
||||
$(cat "$output_dir/claude_response.md")
|
||||
\`\`\`
|
||||
|
||||
## その他のAI
|
||||
$(ls "$output_dir"/*.md | grep -v comparison.md | while read f; do
|
||||
echo "### $(basename "$f" .md)"
|
||||
echo '```'
|
||||
cat "$f"
|
||||
echo '```'
|
||||
done)
|
||||
|
||||
## 分析
|
||||
各AIの回答を比較して、最適なアプローチを選択してください。
|
||||
EOF
|
||||
|
||||
echo -e "${GREEN}✓ 比較結果: $output_dir/comparison.md${NC}"
|
||||
}
|
||||
|
||||
# AIコンテキストチェーン(前のAIの出力を次のAIの入力に)
|
||||
ai_chain() {
|
||||
local initial_prompt="$1"
|
||||
local chain_file="$AI_CONTEXT_DIR/chains/$(date +%Y%m%d-%H%M%S).md"
|
||||
mkdir -p "$(dirname "$chain_file")"
|
||||
|
||||
echo "# AIチェーン実行" > "$chain_file"
|
||||
echo "開始時刻: $(date)" >> "$chain_file"
|
||||
echo "初期プロンプト: $initial_prompt" >> "$chain_file"
|
||||
echo "" >> "$chain_file"
|
||||
|
||||
# Step 1: 設計(仮想的なChatGPT応答)
|
||||
echo "## Step 1: 設計フェーズ" >> "$chain_file"
|
||||
echo "ChatGPTに設計を依頼..." >> "$chain_file"
|
||||
# ここでChatGPT APIを呼ぶか、手動で設計を入力
|
||||
|
||||
# Step 2: 実装(Claude Code)
|
||||
echo -e "${BLUE}Claude Codeで実装中...${NC}"
|
||||
echo "## Step 2: 実装フェーズ (Claude Code)" >> "$chain_file"
|
||||
claude "$initial_prompt を実装してください。前段の設計を参考に。" | tee -a "$chain_file"
|
||||
|
||||
echo -e "${GREEN}✓ AIチェーン完了: $chain_file${NC}"
|
||||
}
|
||||
|
||||
# tmuxセッション管理
|
||||
setup_ai_tmux() {
|
||||
local session_name="ai-workspace"
|
||||
|
||||
# 既存のセッションをチェック
|
||||
if tmux has-session -t "$session_name" 2>/dev/null; then
|
||||
echo -e "${YELLOW}既存のセッションにアタッチします${NC}"
|
||||
tmux attach -t "$session_name"
|
||||
return
|
||||
fi
|
||||
|
||||
# 新しいセッションを作成
|
||||
tmux new-session -d -s "$session_name" -n "claude" "claude --resume"
|
||||
tmux new-window -t "$session_name" -n "editor" "$EDITOR"
|
||||
tmux new-window -t "$session_name" -n "terminal"
|
||||
tmux new-window -t "$session_name" -n "logs" "tail -f $CLAUDE_LOG_DIR/*.log"
|
||||
|
||||
# レイアウト設定
|
||||
tmux select-window -t "$session_name:claude"
|
||||
tmux split-window -h -p 30 "watch -n 1 'ls -la $CLAUDE_LOG_DIR | tail -10'"
|
||||
|
||||
echo -e "${GREEN}✓ tmuxセッション '$session_name' を作成しました${NC}"
|
||||
tmux attach -t "$session_name"
|
||||
}
|
||||
|
||||
# ヘルプメッセージ
|
||||
show_help() {
|
||||
cat << EOF
|
||||
AI統合ヘルパー
|
||||
|
||||
使用方法:
|
||||
$(basename "$0") import <chatgpt_file> [context_name] - ChatGPT会話をインポート
|
||||
$(basename "$0") compare <task> - 複数AIでタスクを実行
|
||||
$(basename "$0") chain <prompt> - AIチェーン実行
|
||||
$(basename "$0") tmux - AI作業用tmuxセッション作成
|
||||
$(basename "$0") help - このヘルプを表示
|
||||
|
||||
例:
|
||||
$(basename "$0") import ~/chatgpt-logs/feature-design.md architecture
|
||||
$(basename "$0") compare "FizzBuzz問題を解いて"
|
||||
$(basename "$0") chain "RESTful APIを設計して実装"
|
||||
$(basename "$0") tmux
|
||||
EOF
|
||||
}
|
||||
|
||||
# メイン処理
|
||||
case "$1" in
|
||||
import)
|
||||
import_chatgpt_conversation "$2" "$3"
|
||||
;;
|
||||
compare)
|
||||
multi_ai_task "$2"
|
||||
;;
|
||||
chain)
|
||||
ai_chain "$2"
|
||||
;;
|
||||
tmux)
|
||||
setup_ai_tmux
|
||||
;;
|
||||
help|--help|-h)
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
Reference in New Issue
Block a user