posimai-root/scripts/aider-run.sh

75 lines
2.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# aider-run.sh — Synology 上で Aider を Docker コンテナとして実行する
#
# 使い方Synology SSH から):
# bash ~/aider-run.sh <repo-name> [aider args...]
#
# 例:
# bash ~/aider-run.sh posimai-diff "fix the CSS bug in .diff-output"
# bash ~/aider-run.sh posimai-brain --message "add dark mode to settings panel"
#
# 必要な環境変数(~/.bashrc または /volume1/homes/mai/.bashrc に設定):
# export GEMINI_API_KEY="your-key-here"
# export GITEA_TOKEN="your-gitea-token"
set -e
REPO_NAME="${1}"
shift || true
AIDER_ARGS="$@"
if [ -z "$REPO_NAME" ]; then
echo "使い方: bash ~/aider-run.sh <repo-name> [aider args...]"
echo "例: bash ~/aider-run.sh posimai-diff \"fix the bug\""
exit 1
fi
WORKSPACE="/tmp/aider-workspace"
REPO_URL="http://100.76.7.3:3000/mai/${REPO_NAME}.git"
DOCKER="/usr/local/bin/docker"
GEMINI_MODEL="gemini-2.5-flash"
# GEMINI_API_KEY チェック
if [ -z "$GEMINI_API_KEY" ]; then
# .env から取得を試みる
if [ -f "/volume1/docker/posimai_lab/.env" ]; then
GEMINI_API_KEY=$(grep '^GEMINI_API_KEY=' /volume1/docker/posimai_lab/.env | cut -d= -f2- | tr -d '"')
fi
fi
if [ -z "$GEMINI_API_KEY" ]; then
echo "[ERROR] GEMINI_API_KEY が設定されていません"
exit 1
fi
# ワークスペース準備
rm -rf "$WORKSPACE/$REPO_NAME"
mkdir -p "$WORKSPACE"
git clone "$REPO_URL" "$WORKSPACE/$REPO_NAME" 2>&1
echo ""
echo "Aider を起動します: $GEMINI_MODEL"
echo "リポジトリ: $REPO_NAME"
echo "引数: ${AIDER_ARGS:-(対話モード)}"
echo ""
$DOCKER run --rm -it \
-e GEMINI_API_KEY="$GEMINI_API_KEY" \
-v "$WORKSPACE/$REPO_NAME:/repo" \
-w /repo \
paulgauthier/aider \
--model "$GEMINI_MODEL" \
--no-check-update \
--no-auto-commits \
--git \
${AIDER_ARGS:+--message "$AIDER_ARGS"}
echo ""
echo "変更を Gitea にプッシュしますか? [y/N]"
read -r answer
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then
cd "$WORKSPACE/$REPO_NAME"
git push origin main
echo "プッシュ完了"
fi