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

163 lines
5.7 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
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
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-pip
python3 --version
- name: Install Cursor CLI
run: |
curl https://cursor.com/install -fsS | bash
export PATH="$HOME/.cursor/bin:$PATH"
echo "$HOME/.cursor/bin" >> $GITHUB_PATH
- 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
run: |
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\"}}"