feat: add memory-push.sh hook and aider-run.sh for Synology

This commit is contained in:
posimai 2026-03-17 22:25:14 +09:00
parent 148041ed07
commit 82fb93fb3b
2 changed files with 99 additions and 0 deletions

74
scripts/aider-run.sh Normal file
View File

@ -0,0 +1,74 @@
#!/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

25
scripts/memory-push.sh Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# memory-push.sh — Claude Code PostToolUse Hook
# Write ツール使用後に memory/ ファイルへの変更を自動コミット&プッシュする
# 環境変数 CLAUDE_TOOL_INPUT (JSON) を stdin 経由で受け取る
MEMORY_DIR="C:/Users/maita/.claude/projects/c--Users-maita-posimai-project/memory"
# stdin から JSON を読み取り、file_path を取得
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('file_path',''))" 2>/dev/null || echo "")
# memory ディレクトリ以外は何もしない
if ! echo "$FILE_PATH" | grep -qi "memory"; then
exit 0
fi
cd "$MEMORY_DIR" || exit 0
# 変更がなければスキップ
git add . 2>/dev/null
git diff --cached --quiet && exit 0
git commit -m "chore: auto-update memory" 2>/dev/null
git push gitea main 2>/dev/null
git push github main 2>/dev/null