mnemo_cards/.forgejo/workflows/agent-planning.yml

247 lines
9.2 KiB
YAML
Raw Normal View History

2025-11-20 21:28:55 +00:00
name: AI Agent - Planning
on:
workflow_dispatch:
inputs:
component:
description: 'Component to plan for'
required: true
type: choice
options:
- web_v2
- backend
- common
2025-11-21 11:13:03 +00:00
llm_model:
description: 'LLM Model'
required: true
default: 'auto'
type: choice
options:
- auto
- composer-1
- sonnet-4.5
- sonnet-4.5-thinking
- gemini-3-pro
- gpt-5
- gpt-5.1
- gpt-5-high
- gpt-5.1-high
- gpt-5-codex
- gpt-5-codex-high
- gpt-5.1-codex
- gpt-5.1-codex-high
- opus-4.1
- grok
2025-11-21 07:18:15 +00:00
schedule:
- cron: '0 */4 * * *'
2025-11-20 21:28:55 +00:00
jobs:
planning:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
2025-11-20 22:15:47 +00:00
- name: Set up Python and bash
2025-11-20 21:55:20 +00:00
run: |
apt-get update -qq
2025-11-20 22:15:47 +00:00
apt-get install -y -qq python3 python3-pip python3-venv bash
2025-11-20 21:55:20 +00:00
python3 --version
pip3 --version
2025-11-20 22:15:47 +00:00
bash --version || echo "bash check failed"
2025-11-20 21:28:55 +00:00
- name: Install Cursor CLI
run: |
2025-11-20 22:15:47 +00:00
# bash should already be installed in previous step
2025-11-20 21:28:55 +00:00
curl https://cursor.com/install -fsS | bash
2025-11-20 22:12:32 +00:00
# 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
2025-11-20 22:04:17 +00:00
# Verify installation
2025-11-20 22:12:32 +00:00
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
2025-11-20 22:04:17 +00:00
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
2025-11-20 22:12:32 +00:00
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"
2025-11-20 22:04:17 +00:00
exit 1
fi
2025-11-20 21:28:55 +00:00
- 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 }}
2025-11-21 11:13:03 +00:00
CURSOR_MODEL: ${{ inputs.llm_model || secrets.CURSOR_MODEL }}
2025-11-20 21:28:55 +00:00
PROJECT_ROOT: ${{ github.workspace }}
MAX_ITERATIONS: 10
2025-11-20 22:22:34 +00:00
PATH: /usr/bin:/bin:$HOME/.local/bin:$HOME/.cursor/bin:${{ env.PATH }}
2025-11-20 21:28:55 +00:00
run: |
2025-11-20 22:22:34 +00:00
# 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
2025-11-20 22:04:17 +00:00
# Verify cursor-agent is accessible
if ! command -v cursor-agent &> /dev/null; then
echo "❌ cursor-agent not found in PATH"
echo "PATH: $PATH"
2025-11-20 22:12:32 +00:00
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
2025-11-20 22:04:17 +00:00
export PATH="$HOME/.cursor/bin:$PATH"
2025-11-20 22:12:32 +00:00
echo "✅ Found at $HOME/.cursor/bin/cursor-agent"
2025-11-20 22:04:17 +00:00
else
2025-11-20 22:12:32 +00:00
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"
2025-11-20 22:04:17 +00:00
exit 1
fi
2025-11-20 22:22:34 +00:00
else
echo "✅ cursor-agent found at: $(command -v cursor-agent)"
2025-11-20 22:04:17 +00:00
fi
2025-11-20 21:28:55 +00:00
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\"}}"