mnemo_cards/.forgejo/workflows/agent-planning.yml
2025-11-21 01:22:34 +03:00

223 lines
8.7 KiB
YAML

name: AI Agent - Planning
on:
workflow_dispatch:
inputs:
component:
description: 'Component to plan for'
required: true
type: choice
options:
- web_v2
- backend
- common
jobs:
planning:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python and bash
run: |
apt-get update -qq
apt-get install -y -qq python3 python3-pip python3-venv bash
python3 --version
pip3 --version
bash --version || echo "bash check failed"
- name: Install Cursor CLI
run: |
# bash should already be installed in previous step
curl https://cursor.com/install -fsS | bash
# Cursor installs to ~/.local/bin by default
export PATH="$HOME/.local/bin:$PATH"
echo "$HOME/.local/bin" >> $GITHUB_PATH
# Also check ~/.cursor/bin (older location)
if [ -d "$HOME/.cursor/bin" ]; then
export PATH="$HOME/.cursor/bin:$PATH"
echo "$HOME/.cursor/bin" >> $GITHUB_PATH
fi
# Verify installation
if [ -f "$HOME/.local/bin/cursor-agent" ]; then
echo "✅ Cursor CLI installed at $HOME/.local/bin/cursor-agent"
chmod +x "$HOME/.local/bin/cursor-agent"
"$HOME/.local/bin/cursor-agent" --version || echo "cursor-agent executable found but version check failed"
elif [ -f "$HOME/.cursor/bin/cursor-agent" ]; then
echo "✅ Cursor CLI installed at $HOME/.cursor/bin/cursor-agent"
chmod +x "$HOME/.cursor/bin/cursor-agent"
"$HOME/.cursor/bin/cursor-agent" --version || echo "cursor-agent executable found but version check failed"
else
echo "❌ Cursor CLI not found in expected locations"
echo "Checking PATH..."
command -v cursor-agent || echo "cursor-agent not in PATH"
find "$HOME" -name "cursor-agent" -type f 2>/dev/null | head -5 || echo "No cursor-agent found in $HOME"
exit 1
fi
- name: Configure Git
run: |
git config --global user.name "AI Agent"
git config --global user.email "ai-agent@mnemo-cards.com"
- name: Run Planning Agent
env:
CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}
CURSOR_MODEL: ${{ secrets.CURSOR_MODEL }}
PROJECT_ROOT: ${{ github.workspace }}
MAX_ITERATIONS: 10
PATH: /usr/bin:/bin:$HOME/.local/bin:$HOME/.cursor/bin:${{ env.PATH }}
run: |
# Ensure bash and cursor-agent are in PATH for this step
export PATH="/usr/bin:/bin:$HOME/.local/bin:$HOME/.cursor/bin:$PATH"
# Verify bash is accessible
if ! command -v bash &> /dev/null; then
echo "❌ bash not found in PATH"
echo "PATH: $PATH"
echo "Looking for bash..."
find /usr /bin -name "bash" -type f 2>/dev/null | head -5 || echo "No bash found"
exit 1
else
echo "✅ bash found at: $(command -v bash)"
bash --version || echo "bash version check failed"
fi
# Verify cursor-agent is accessible
if ! command -v cursor-agent &> /dev/null; then
echo "❌ cursor-agent not found in PATH"
echo "PATH: $PATH"
echo "Trying full paths..."
if [ -f "$HOME/.local/bin/cursor-agent" ]; then
export PATH="$HOME/.local/bin:$PATH"
echo "✅ Found at $HOME/.local/bin/cursor-agent"
elif [ -f "$HOME/.cursor/bin/cursor-agent" ]; then
export PATH="$HOME/.cursor/bin:$PATH"
echo "✅ Found at $HOME/.cursor/bin/cursor-agent"
else
echo "❌ cursor-agent not found in any expected location"
find "$HOME" -name "cursor-agent" -type f 2>/dev/null | head -5 || echo "No cursor-agent found"
exit 1
fi
else
echo "✅ cursor-agent found at: $(command -v cursor-agent)"
fi
cd ${{ github.workspace }}
python3 tools/agent/planning_agent.py ${{ inputs.component }}
- name: Parse Task List and Create Summary
if: success()
id: parse_tasks
run: |
COMPONENT="${{ inputs.component }}"
TASK_LIST_PATH="ai_docs/agent/${COMPONENT}/task_list.json"
if [ ! -f "$TASK_LIST_PATH" ]; then
echo "Task list not found"
exit 0
fi
# Parse JSON with Python
python3 << 'EOF'
import json
import os
component = os.environ.get('COMPONENT', 'unknown')
task_list_path = f"ai_docs/agent/{component}/task_list.json"
try:
with open(task_list_path, 'r') as f:
data = json.load(f)
tasks = data.get('tasks', [])
high = sum(1 for t in tasks if t.get('priority') == 'high')
medium = sum(1 for t in tasks if t.get('priority') == 'medium')
low = sum(1 for t in tasks if t.get('priority') == 'low')
total_hours = sum(t.get('estimated_hours', 0) for t in tasks)
# Create issue body
body = f"# 🎯 Planning Summary: {component}\\n\\n"
body += f"**Generated:** {data.get('generated_at', 'N/A')}\\n"
body += f"**Total Tasks:** {len(tasks)}\\n"
body += f"**Estimated Hours:** {total_hours:.1f}h\\n\\n"
body += "## Priority Breakdown\\n\\n"
body += f"- 🔴 **HIGH:** {high} tasks\\n"
body += f"- 🟡 **MEDIUM:** {medium} tasks\\n"
body += f"- 🟢 **LOW:** {low} tasks\\n\\n"
high_tasks = [t for t in tasks if t.get('priority') == 'high']
if high_tasks:
body += "## 🔴 High Priority Tasks\\n\\n"
for task in high_tasks:
body += f"### {task['id']}: {task['title']}\\n"
body += f"- **Estimated:** {task['estimated_hours']}h\\n"
body += f"- **Status:** {task['status']}\\n"
desc = task['description'][:200]
body += f"- **Description:** {desc}...\\n\\n"
body += "\\n---\\n*Generated by AI Planning Agent*"
# Save to file for next step
with open('/tmp/issue_body.txt', 'w') as f:
f.write(body)
title = f"📋 Planning: {component} - {len(tasks)} tasks ({total_hours:.1f}h)"
with open('/tmp/issue_title.txt', 'w') as f:
f.write(title)
print(f"Tasks: {len(tasks)}, High: {high}, Medium: {medium}, Low: {low}")
except Exception as e:
print(f"Error: {e}")
exit(1)
EOF
env:
COMPONENT: ${{ inputs.component }}
- name: Create Issue via Forgejo API
if: success()
run: |
COMPONENT="${{ inputs.component }}"
if [ ! -f "/tmp/issue_body.txt" ] || [ ! -f "/tmp/issue_title.txt" ]; then
echo "Issue files not found, skipping issue creation"
exit 0
fi
TITLE=$(cat /tmp/issue_title.txt)
BODY=$(cat /tmp/issue_body.txt)
# Forgejo API endpoint (adjust to your Forgejo instance)
API_URL="${{ github.api_url }}/repos/${{ github.repository }}/issues"
# Create issue using curl
curl -X POST "$API_URL" \
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
-H "Content-Type: application/json" \
-d @- << EOF
{
"title": "$TITLE",
"body": $(echo "$BODY" | jq -Rs .),
"labels": ["ai-agent", "planning", "$COMPONENT"]
}
EOF
- name: Trigger Development Workflow
if: success()
run: |
COMPONENT="${{ inputs.component }}"
# Trigger via Forgejo API
API_URL="${{ github.api_url }}/repos/${{ github.repository }}/actions/workflows/agent-development.yml/dispatches"
curl -X POST "$API_URL" \
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"ref\":\"master\",\"inputs\":{\"component\":\"$COMPONENT\"}}"