Spaces:
Sleeping
Sleeping
Deminiko commited on
Commit ·
db0133b
1
Parent(s): a05d7b0
docs: Add comprehensive documentation and testing guides
Browse files- Add TESTING.md with detailed test scenarios and procedures
- Add setup-hf.sh for HF Spaces configuration assistance
- Update main README.md with complete project information
- Include API endpoints documentation
- Add troubleshooting guides
- Document GitHub App authentication process
- Add testing checklist and success criteria
- README.md +217 -47
- public/TESTING.md +321 -0
- public/setup-hf.sh +69 -0
README.md
CHANGED
|
@@ -1,72 +1,242 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
-
pinned:
|
| 8 |
-
short_description:
|
| 9 |
---
|
| 10 |
|
| 11 |
-
#
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
## Features
|
| 16 |
|
| 17 |
-
|
| 18 |
-
-
|
| 19 |
-
-
|
| 20 |
-
-
|
| 21 |
-
-
|
| 22 |
-
- 🔄 Auto-sync from GitHub to Hugging Face
|
| 23 |
|
| 24 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
-
|
| 28 |
-
-
|
| 29 |
-
-
|
| 30 |
-
-
|
| 31 |
-
- Docker
|
| 32 |
|
| 33 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: AI Agent for GitHub Project Management
|
| 3 |
+
emoji: 🤖
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: docker
|
| 7 |
+
pinned: true
|
| 8 |
+
short_description: AI-powered project scanning, documentation, and chat interface
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# AI Agent for Hugging Face Spaces
|
| 12 |
|
| 13 |
+
An intelligent AI agent that scans GitHub projects, generates documentation, detects issues, and provides a chat interface - all powered by Google Generative AI (Gemini).
|
| 14 |
|
| 15 |
+
## 🎯 Features
|
| 16 |
|
| 17 |
+
### 🤖 Automated Project Scanning
|
| 18 |
+
- Periodically scans project structure
|
| 19 |
+
- Detects missing critical files (package.json, README, Dockerfile)
|
| 20 |
+
- Identifies potential issues and improvements
|
| 21 |
+
- Creates GitHub issues with recommendations
|
|
|
|
| 22 |
|
| 23 |
+
### 📚 Auto-Generated Documentation
|
| 24 |
+
- Generates project documentation
|
| 25 |
+
- Creates comprehensive README files
|
| 26 |
+
- Documents individual source files
|
| 27 |
+
- Explains architecture and features
|
| 28 |
|
| 29 |
+
### 💬 AI Chat Interface
|
| 30 |
+
- Chat with Gemini AI about your project
|
| 31 |
+
- Ask questions about code and architecture
|
| 32 |
+
- Get recommendations and insights
|
| 33 |
+
- Web-based chat interface
|
|
|
|
| 34 |
|
| 35 |
+
### 🔐 Secure GitHub Integration
|
| 36 |
+
- GitHub App authentication (recommended)
|
| 37 |
+
- Personal access token fallback
|
| 38 |
+
- Read/write repository access
|
| 39 |
+
- Automatic workflow integration
|
| 40 |
|
| 41 |
+
## 🛠️ Technology Stack
|
| 42 |
+
|
| 43 |
+
- **Backend**: Node.js 18+ with Express.js
|
| 44 |
+
- **AI**: Google Generative AI (Gemini)
|
| 45 |
+
- **GitHub**: Octokit API with GitHub App auth
|
| 46 |
+
- **Frontend**: Vanilla HTML/CSS/JavaScript
|
| 47 |
+
- **Deployment**: Docker on Hugging Face Spaces
|
| 48 |
+
- **CI/CD**: GitHub Actions for auto-sync
|
| 49 |
+
|
| 50 |
+
## 📦 Project Structure
|
| 51 |
+
|
| 52 |
+
```
|
| 53 |
+
.
|
| 54 |
+
├── Dockerfile # Container configuration
|
| 55 |
+
├── .github/workflows/sync-to-hf.yml # Auto-sync pipeline
|
| 56 |
+
├── public/ # Web server root
|
| 57 |
+
│ ├── src/
|
| 58 |
+
│ │ ├── server.js # Express app entry point
|
| 59 |
+
│ │ ├── config/ # Configuration management
|
| 60 |
+
│ │ ├── services/ # GitHub, Gemini, Project services
|
| 61 |
+
│ │ ├── agents/ # Scanner and Doc Generator agents
|
| 62 |
+
│ │ ├── api/ # REST API endpoints
|
| 63 |
+
│ │ └── utils/ # Utilities (logging, task runner)
|
| 64 |
+
│ ├── assets/ # CSS and JS modules
|
| 65 |
+
│ ├── index.html # Web UI
|
| 66 |
+
│ ├── package.json # Node.js dependencies
|
| 67 |
+
│ └── INSTALLATION.md # Setup guide
|
| 68 |
+
├── scripts/ # Utility scripts
|
| 69 |
+
│ ├── get-installation-token.js # GitHub App token generation
|
| 70 |
+
│ ├── test-github-auth.js # Auth validation
|
| 71 |
+
│ └── test-ai-agent.js # Comprehensive test suite
|
| 72 |
+
└── README.md # This file
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## 🚀 Quick Start
|
| 76 |
+
|
| 77 |
+
### Prerequisites
|
| 78 |
+
- Node.js 18 or higher
|
| 79 |
+
- npm or yarn
|
| 80 |
+
- Docker (for containerized deployment)
|
| 81 |
+
- Git
|
| 82 |
+
|
| 83 |
+
### Local Development
|
| 84 |
+
|
| 85 |
+
1. **Install dependencies**
|
| 86 |
+
```bash
|
| 87 |
+
cd public
|
| 88 |
+
npm install
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
2. **Configure environment**
|
| 92 |
+
```bash
|
| 93 |
+
cp .env.example .env
|
| 94 |
+
# Edit .env with your API keys
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
3. **Start the server**
|
| 98 |
+
```bash
|
| 99 |
+
npm start
|
| 100 |
+
# Server runs on http://localhost:7860
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
4. **Run tests**
|
| 104 |
+
```bash
|
| 105 |
+
# In another terminal
|
| 106 |
+
node scripts/test-ai-agent.js
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### Docker Deployment
|
| 110 |
|
| 111 |
```bash
|
| 112 |
+
# Build image
|
| 113 |
+
docker build -t ai-agent-hf:latest .
|
| 114 |
+
|
| 115 |
+
# Run container
|
| 116 |
+
docker run -p 7860:7860 \
|
| 117 |
+
-e GEMINI_API_KEY=your_key \
|
| 118 |
+
-e GH_APP_ID=your_id \
|
| 119 |
+
-e GH_APP_PRIVATE_KEY_B64=your_key \
|
| 120 |
+
-e GH_APP_INSTALLATION_ID=your_id \
|
| 121 |
+
ai-agent-hf:latest
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
## ⚙️ Configuration
|
| 125 |
+
|
| 126 |
+
### Environment Variables
|
| 127 |
+
|
| 128 |
+
**Required:**
|
| 129 |
+
- `GEMINI_API_KEY`: Get from https://makersuite.google.com/app/apikey
|
| 130 |
+
- **GitHub Auth** (choose one):
|
| 131 |
+
- `GITHUB_TOKEN`: Personal access token (https://github.com/settings/tokens)
|
| 132 |
+
- OR GitHub App:
|
| 133 |
+
- `GH_APP_ID`: Your GitHub App ID
|
| 134 |
+
- `GH_APP_PRIVATE_KEY_B64`: Base64-encoded private key
|
| 135 |
+
- `GH_APP_INSTALLATION_ID`: Installation ID
|
| 136 |
|
| 137 |
+
**Optional:**
|
| 138 |
+
- `ENABLE_AUTO_FIX`: Enable periodic scanning (default: false)
|
| 139 |
+
- `SCAN_INTERVAL`: Scan interval in ms (default: 3600000 = 1 hour)
|
| 140 |
+
- `NODE_ENV`: Environment (default: production)
|
| 141 |
+
|
| 142 |
+
### GitHub App Setup
|
| 143 |
+
|
| 144 |
+
See [INSTALLATION.md](public/INSTALLATION.md) for complete GitHub App setup instructions.
|
| 145 |
+
|
| 146 |
+
## 📡 API Endpoints
|
| 147 |
+
|
| 148 |
+
### Health Check
|
| 149 |
+
```bash
|
| 150 |
+
GET /health
|
| 151 |
```
|
| 152 |
|
| 153 |
+
### Chat API
|
| 154 |
+
```bash
|
| 155 |
+
POST /api/chat/send
|
| 156 |
+
Content-Type: application/json
|
| 157 |
|
| 158 |
+
{
|
| 159 |
+
"message": "What does this project do?"
|
| 160 |
+
}
|
| 161 |
+
```
|
| 162 |
|
| 163 |
+
### Scanner API
|
| 164 |
+
```bash
|
| 165 |
+
POST /api/scanner/scan # Trigger manual scan
|
| 166 |
+
GET /api/scanner/last-report # Get last scan results
|
| 167 |
```
|
| 168 |
+
|
| 169 |
+
### Documentation API
|
| 170 |
+
```bash
|
| 171 |
+
POST /api/docs/project # Generate project docs
|
| 172 |
+
POST /api/docs/file # Document specific file
|
| 173 |
+
POST /api/docs/readme # Generate README
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
## 🧪 Testing
|
| 177 |
+
|
| 178 |
+
Run the comprehensive test suite:
|
| 179 |
+
|
| 180 |
+
```bash
|
| 181 |
+
node scripts/test-ai-agent.js
|
| 182 |
```
|
| 183 |
|
| 184 |
+
Tests validate:
|
| 185 |
+
- ✓ Server health and availability
|
| 186 |
+
- ✓ Project scanning functionality
|
| 187 |
+
- ✓ Documentation generation
|
| 188 |
+
- ✓ Chat interface
|
| 189 |
+
- ✓ GitHub integration
|
| 190 |
+
|
| 191 |
+
See [TESTING.md](public/TESTING.md) for detailed testing documentation.
|
| 192 |
+
|
| 193 |
+
## 🌐 Hugging Face Spaces Deployment
|
| 194 |
+
|
| 195 |
+
### Setup
|
| 196 |
+
|
| 197 |
+
1. Create a new Space on Hugging Face with Docker SDK
|
| 198 |
+
2. Add these secrets in Space settings:
|
| 199 |
+
- `HF_TOKEN`: Your HF write token
|
| 200 |
+
- `HF_USERNAME`: Your HF username
|
| 201 |
+
- `HF_SPACE_NAME`: Your space name
|
| 202 |
+
- `GEMINI_API_KEY`: Your Gemini API key
|
| 203 |
+
- GitHub authentication (choose method)
|
| 204 |
+
|
| 205 |
+
3. Push to GitHub - auto-syncs to HF Space
|
| 206 |
+
|
| 207 |
+
### Access
|
| 208 |
+
|
| 209 |
+
- **Web UI**: https://huggingface.co/spaces/{username}/{space-name}
|
| 210 |
+
- **Health Check**: https://{username}-{space-name}.hf.space/health
|
| 211 |
+
- **API Base**: https://{username}-{space-name}.hf.space/api
|
| 212 |
+
|
| 213 |
+
## 📖 Documentation
|
| 214 |
+
|
| 215 |
+
- [INSTALLATION.md](public/INSTALLATION.md) - Detailed setup guide
|
| 216 |
+
- [TESTING.md](public/TESTING.md) - Testing procedures
|
| 217 |
+
- [ARCHITECTURE.md](public/ARCHITECTURE.md) - System design
|
| 218 |
+
|
| 219 |
+
## 🤝 Contributing
|
| 220 |
+
|
| 221 |
+
1. Fork the repository
|
| 222 |
+
2. Create a feature branch
|
| 223 |
+
3. Make your changes
|
| 224 |
+
4. Push and create a Pull Request
|
| 225 |
+
|
| 226 |
+
## 📝 License
|
| 227 |
+
|
| 228 |
+
MIT License - See LICENSE file for details
|
| 229 |
|
| 230 |
+
## 🔗 Links
|
| 231 |
|
| 232 |
+
- **GitHub**: https://github.com/NLarchive/my-webapp-hf
|
| 233 |
+
- **Hugging Face**: https://huggingface.co/spaces/NLarchive/my-webapp-hf
|
| 234 |
+
- **Google Generative AI**: https://makersuite.google.com
|
| 235 |
|
| 236 |
+
## ⚠️ Important Notes
|
| 237 |
|
| 238 |
+
- Never commit `.env` files with real tokens
|
| 239 |
+
- Use GitHub secrets for sensitive values
|
| 240 |
+
- Keep private keys encrypted and base64-encoded
|
| 241 |
+
- Monitor API usage and quota limits
|
| 242 |
+
- Review generated documentation before publishing
|
public/TESTING.md
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
npm install
|
| 11 |
+
|
| 12 |
+
# Create .env file with test values
|
| 13 |
+
cp .env.example .env
|
| 14 |
+
# Edit .env with your API keys
|
| 15 |
+
|
| 16 |
+
# Start the server
|
| 17 |
+
npm start
|
| 18 |
+
# Server will run on http://localhost:7860
|
| 19 |
+
|
| 20 |
+
# In another terminal, run tests
|
| 21 |
+
node scripts/test-ai-agent.js
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
### 2. Expected Test Results
|
| 25 |
+
|
| 26 |
+
The test suite validates:
|
| 27 |
+
- ✓ **Health Check**: Server responds to health endpoint
|
| 28 |
+
- ✓ **Project Scanning**: AI scans project structure for issues
|
| 29 |
+
- ✓ **Documentation Generation**: Auto-generates project documentation
|
| 30 |
+
- ✓ **README Generation**: Creates comprehensive README
|
| 31 |
+
- ✓ **Chat Interface**: Gemini AI responds to chat messages
|
| 32 |
+
- ✓ **Scanner Reports**: Retrieves scan history
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## Testing Scenario: Auto-Modification Features
|
| 37 |
+
|
| 38 |
+
### Test Case 1: Project Documentation
|
| 39 |
+
|
| 40 |
+
**What it does:**
|
| 41 |
+
- Analyzes project structure
|
| 42 |
+
- Generates documentation about files and directories
|
| 43 |
+
- Provides insights about the codebase
|
| 44 |
+
|
| 45 |
+
**Test:**
|
| 46 |
+
```bash
|
| 47 |
+
curl -X POST http://localhost:7860/api/docs/project \
|
| 48 |
+
-H "Content-Type: application/json"
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
**Expected Output:**
|
| 52 |
+
```json
|
| 53 |
+
{
|
| 54 |
+
"success": true,
|
| 55 |
+
"documentation": "Project overview, directory explanation, getting started...",
|
| 56 |
+
"timestamp": "2025-11-19T10:30:00.000Z"
|
| 57 |
+
}
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
---
|
| 61 |
+
|
| 62 |
+
### Test Case 2: Automatic Issue Detection
|
| 63 |
+
|
| 64 |
+
**What it does:**
|
| 65 |
+
- Scans for missing critical files (package.json, README, Dockerfile)
|
| 66 |
+
- Detects dependency issues
|
| 67 |
+
- Identifies documentation gaps
|
| 68 |
+
|
| 69 |
+
**Test:**
|
| 70 |
+
```bash
|
| 71 |
+
curl -X POST http://localhost:7860/api/scanner/scan \
|
| 72 |
+
-H "Content-Type: application/json"
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
**Expected Output:**
|
| 76 |
+
```json
|
| 77 |
+
{
|
| 78 |
+
"success": true,
|
| 79 |
+
"report": {
|
| 80 |
+
"timestamp": "2025-11-19T10:30:00.000Z",
|
| 81 |
+
"duration": 2345,
|
| 82 |
+
"structure": {
|
| 83 |
+
"files": [...],
|
| 84 |
+
"directories": [...]
|
| 85 |
+
},
|
| 86 |
+
"issues": [...],
|
| 87 |
+
"analysis": {...},
|
| 88 |
+
"recommendations": [...]
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
---
|
| 94 |
+
|
| 95 |
+
### Test Case 3: README Auto-Generation
|
| 96 |
+
|
| 97 |
+
**What it does:**
|
| 98 |
+
- Creates professional README with sections:
|
| 99 |
+
- Project description
|
| 100 |
+
- Features
|
| 101 |
+
- Installation
|
| 102 |
+
- Configuration
|
| 103 |
+
- API documentation
|
| 104 |
+
- Architecture
|
| 105 |
+
|
| 106 |
+
**Test:**
|
| 107 |
+
```bash
|
| 108 |
+
curl -X POST http://localhost:7860/api/docs/readme \
|
| 109 |
+
-H "Content-Type: application/json"
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
**Expected Output:**
|
| 113 |
+
```json
|
| 114 |
+
{
|
| 115 |
+
"success": true,
|
| 116 |
+
"readme": "# Project Name\n\nDescr..."
|
| 117 |
+
}
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
### Test Case 4: File-Specific Documentation
|
| 123 |
+
|
| 124 |
+
**What it does:**
|
| 125 |
+
- Analyzes individual source files
|
| 126 |
+
- Generates documentation about functions and exports
|
| 127 |
+
- Provides usage examples
|
| 128 |
+
|
| 129 |
+
**Test:**
|
| 130 |
+
```bash
|
| 131 |
+
curl -X POST http://localhost:7860/api/docs/file \
|
| 132 |
+
-H "Content-Type: application/json" \
|
| 133 |
+
-d '{"filePath": "src/server.js"}'
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
---
|
| 137 |
+
|
| 138 |
+
### Test Case 5: Chat-Based Assistance
|
| 139 |
+
|
| 140 |
+
**What it does:**
|
| 141 |
+
- Accepts natural language questions
|
| 142 |
+
- Provides AI-powered responses about code
|
| 143 |
+
- Explains architecture and functionality
|
| 144 |
+
|
| 145 |
+
**Test:**
|
| 146 |
+
```bash
|
| 147 |
+
curl -X POST http://localhost:7860/api/chat/send \
|
| 148 |
+
-H "Content-Type: application/json" \
|
| 149 |
+
-d '{"message": "What does the scanner agent do?"}'
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
---
|
| 153 |
+
|
| 154 |
+
## Testing on Hugging Face Spaces
|
| 155 |
+
|
| 156 |
+
### Prerequisites
|
| 157 |
+
1. Create HF Space (Settings → Secrets)
|
| 158 |
+
2. Add these secrets:
|
| 159 |
+
- `HF_TOKEN`: Your HF write token
|
| 160 |
+
- `HF_USERNAME`: Your HF username
|
| 161 |
+
- `HF_SPACE_NAME`: Your space name
|
| 162 |
+
- `GEMINI_API_KEY`: Your Gemini API key
|
| 163 |
+
- `GH_APP_ID`: GitHub App ID (if using GitHub App)
|
| 164 |
+
- `GH_APP_PRIVATE_KEY_B64`: Base64 private key
|
| 165 |
+
- `GH_APP_INSTALLATION_ID`: App installation ID
|
| 166 |
+
|
| 167 |
+
### Testing Steps
|
| 168 |
+
|
| 169 |
+
1. **Push to GitHub** (auto-syncs to HF):
|
| 170 |
+
```bash
|
| 171 |
+
git push origin main
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
2. **Check HF Space** (wait 2-3 minutes for sync):
|
| 175 |
+
- Go to your HF Space
|
| 176 |
+
- Check "Logs" tab for deployment status
|
| 177 |
+
|
| 178 |
+
3. **Test Health Endpoint**:
|
| 179 |
+
```bash
|
| 180 |
+
curl https://{username}-{space-name}.hf.space/health
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
4. **Test Scanner**:
|
| 184 |
+
```bash
|
| 185 |
+
curl -X POST https://{username}-{space-name}.hf.space/api/scanner/scan
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
5. **Test Chat**:
|
| 189 |
+
- Open the web interface at `https://{username}-{space-name}.hf.space`
|
| 190 |
+
- Type a message and chat with the AI
|
| 191 |
+
|
| 192 |
+
---
|
| 193 |
+
|
| 194 |
+
## Expected Behaviors
|
| 195 |
+
|
| 196 |
+
### On First Scan
|
| 197 |
+
- Project structure is analyzed
|
| 198 |
+
- Documentation is generated
|
| 199 |
+
- Issues are detected
|
| 200 |
+
- Recommendations are provided
|
| 201 |
+
|
| 202 |
+
### Periodic Scanning
|
| 203 |
+
- If `ENABLE_AUTO_FIX=true`, scans run every hour (configurable)
|
| 204 |
+
- Results are logged to console
|
| 205 |
+
- GitHub issues are created for critical problems
|
| 206 |
+
|
| 207 |
+
### Documentation Generation
|
| 208 |
+
- Auto-generates for missing documentation
|
| 209 |
+
- Updates can be reviewed in GitHub issues
|
| 210 |
+
- Helps team understand codebase
|
| 211 |
+
|
| 212 |
+
---
|
| 213 |
+
|
| 214 |
+
## Troubleshooting
|
| 215 |
+
|
| 216 |
+
### Health Check Fails
|
| 217 |
+
```bash
|
| 218 |
+
# Check if port 7860 is available
|
| 219 |
+
# Check server logs for startup errors
|
| 220 |
+
# Verify all environment variables are set
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
### Chat API Returns Error
|
| 224 |
+
```bash
|
| 225 |
+
# Check GEMINI_API_KEY is valid
|
| 226 |
+
# Check API quota isn't exceeded
|
| 227 |
+
# Verify network connectivity
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
### GitHub Issues Not Created
|
| 231 |
+
```bash
|
| 232 |
+
# Verify GitHub authentication (GITHUB_TOKEN or GitHub App)
|
| 233 |
+
# Check GITHUB_REPO and GITHUB_OWNER are correct
|
| 234 |
+
# Verify app has repository permissions
|
| 235 |
+
```
|
| 236 |
+
|
| 237 |
+
### Scanner Doesn't Run
|
| 238 |
+
```bash
|
| 239 |
+
# Check ENABLE_AUTO_FIX=true
|
| 240 |
+
# Verify project is accessible from API
|
| 241 |
+
# Check logs for detailed error messages
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
---
|
| 245 |
+
|
| 246 |
+
## Manual Testing Checklist
|
| 247 |
+
|
| 248 |
+
- [ ] Health endpoint responds with status
|
| 249 |
+
- [ ] Project structure is retrieved correctly
|
| 250 |
+
- [ ] Documentation generates without errors
|
| 251 |
+
- [ ] README is created with proper formatting
|
| 252 |
+
- [ ] Chat responds to user messages
|
| 253 |
+
- [ ] Scanner detects project issues
|
| 254 |
+
- [ ] Reports include recommendations
|
| 255 |
+
- [ ] On HF Space: Web UI loads
|
| 256 |
+
- [ ] On HF Space: Chat accepts input
|
| 257 |
+
- [ ] On HF Space: All endpoints are accessible
|
| 258 |
+
|
| 259 |
+
---
|
| 260 |
+
|
| 261 |
+
## Advanced Testing
|
| 262 |
+
|
| 263 |
+
### Load Testing
|
| 264 |
+
```bash
|
| 265 |
+
# Test concurrent requests
|
| 266 |
+
for i in {1..5}; do
|
| 267 |
+
curl -X POST http://localhost:7860/api/scanner/scan &
|
| 268 |
+
done
|
| 269 |
+
wait
|
| 270 |
+
```
|
| 271 |
+
|
| 272 |
+
### API Response Time
|
| 273 |
+
```bash
|
| 274 |
+
# Measure endpoint performance
|
| 275 |
+
time curl -X POST http://localhost:7860/api/docs/project
|
| 276 |
+
```
|
| 277 |
+
|
| 278 |
+
### Memory Usage
|
| 279 |
+
```bash
|
| 280 |
+
# Monitor while running tests
|
| 281 |
+
watch -n 1 'ps aux | grep node'
|
| 282 |
+
```
|
| 283 |
+
|
| 284 |
+
---
|
| 285 |
+
|
| 286 |
+
## Success Criteria
|
| 287 |
+
|
| 288 |
+
✅ **Basic Functionality**
|
| 289 |
+
- Server starts without errors
|
| 290 |
+
- All endpoints respond with valid JSON
|
| 291 |
+
- Health check returns status
|
| 292 |
+
|
| 293 |
+
✅ **AI Features**
|
| 294 |
+
- Scanner finds project structure
|
| 295 |
+
- Documentation generates meaningful content
|
| 296 |
+
- Chat AI responds appropriately
|
| 297 |
+
- Recommendations are actionable
|
| 298 |
+
|
| 299 |
+
✅ **GitHub Integration**
|
| 300 |
+
- Can authenticate to GitHub
|
| 301 |
+
- Can read repository contents
|
| 302 |
+
- Can create issues (if configured)
|
| 303 |
+
|
| 304 |
+
✅ **HF Deployment**
|
| 305 |
+
- Docker builds successfully
|
| 306 |
+
- Application runs on HF Space
|
| 307 |
+
- Web UI is accessible
|
| 308 |
+
- All features work on remote instance
|
| 309 |
+
|
| 310 |
+
---
|
| 311 |
+
|
| 312 |
+
## Next Steps
|
| 313 |
+
|
| 314 |
+
1. ✅ Complete GitHub App setup
|
| 315 |
+
2. ✅ Deploy to HF Space
|
| 316 |
+
3. ✅ Run test suite
|
| 317 |
+
4. ✅ Monitor logs for errors
|
| 318 |
+
5. ✅ Test with real projects
|
| 319 |
+
6. 📋 Create CI/CD pipeline
|
| 320 |
+
7. 📋 Add webhook integration
|
| 321 |
+
8. 📋 Implement auto-fixes
|
public/setup-hf.sh
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# HF Spaces Quick Setup Script
|
| 4 |
+
# This script helps set up environment variables for HF Spaces deployment
|
| 5 |
+
|
| 6 |
+
set -e
|
| 7 |
+
|
| 8 |
+
echo "╔═══════════════════════════════════════════════════════════╗"
|
| 9 |
+
echo "║ HF Spaces - AI Agent Setup Helper ║"
|
| 10 |
+
echo "╚═══════════════════════════════════════════════════════════╝"
|
| 11 |
+
echo ""
|
| 12 |
+
|
| 13 |
+
# Check if running in HF Spaces environment
|
| 14 |
+
if [ -z "$SPACE_ID" ]; then
|
| 15 |
+
echo "⚠️ Warning: Not running in HF Spaces environment"
|
| 16 |
+
echo "This script should be run from HF Spaces terminal"
|
| 17 |
+
echo ""
|
| 18 |
+
fi
|
| 19 |
+
|
| 20 |
+
echo "Required Environment Variables:"
|
| 21 |
+
echo "================================"
|
| 22 |
+
echo ""
|
| 23 |
+
echo "1. GEMINI_API_KEY"
|
| 24 |
+
echo " - Get from: https://makersuite.google.com/app/apikey"
|
| 25 |
+
echo " - Add to HF Space Secrets"
|
| 26 |
+
echo ""
|
| 27 |
+
|
| 28 |
+
echo "2. GitHub Authentication (Choose ONE):"
|
| 29 |
+
echo ""
|
| 30 |
+
echo " Option A: Personal Access Token"
|
| 31 |
+
echo " - GITHUB_TOKEN: https://github.com/settings/tokens"
|
| 32 |
+
echo ""
|
| 33 |
+
echo " Option B: GitHub App (Recommended)"
|
| 34 |
+
echo " - GH_APP_ID: Your GitHub App ID"
|
| 35 |
+
echo " - GH_APP_PRIVATE_KEY_B64: Base64 encoded private key"
|
| 36 |
+
echo " - GH_APP_INSTALLATION_ID: App installation ID"
|
| 37 |
+
echo ""
|
| 38 |
+
|
| 39 |
+
echo "3. Hugging Face Configuration"
|
| 40 |
+
echo " - HF_TOKEN: https://huggingface.co/settings/tokens"
|
| 41 |
+
echo " - HF_USERNAME: Your HF username"
|
| 42 |
+
echo " - HF_SPACE_NAME: This space's name"
|
| 43 |
+
echo ""
|
| 44 |
+
|
| 45 |
+
echo "4. Optional Configuration"
|
| 46 |
+
echo " - ENABLE_AUTO_FIX: true/false (auto-scan for issues)"
|
| 47 |
+
echo " - SCAN_INTERVAL: milliseconds between scans (default: 3600000)"
|
| 48 |
+
echo " - NODE_ENV: production/development"
|
| 49 |
+
echo ""
|
| 50 |
+
|
| 51 |
+
echo "Setup Instructions:"
|
| 52 |
+
echo "==================="
|
| 53 |
+
echo "1. Go to Settings → Secrets"
|
| 54 |
+
echo "2. Add each variable with its value"
|
| 55 |
+
echo "3. Click Save"
|
| 56 |
+
echo "4. Space will restart with new configuration"
|
| 57 |
+
echo ""
|
| 58 |
+
|
| 59 |
+
echo "Verification:"
|
| 60 |
+
echo "============="
|
| 61 |
+
echo ""
|
| 62 |
+
echo "Check if server is running:"
|
| 63 |
+
echo " curl http://localhost:7860/health"
|
| 64 |
+
echo ""
|
| 65 |
+
echo "View application logs:"
|
| 66 |
+
echo " tail -f /tmp/*.log"
|
| 67 |
+
echo ""
|
| 68 |
+
|
| 69 |
+
echo "✓ Setup complete! Your AI Agent is ready."
|