File size: 6,517 Bytes
89ba5b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# SecureHeal Arena - API Reference

Complete reference for every endpoint exposed by the SecureHeal Agent backend on Hugging Face Spaces.

**Base URL:** `https://ravindraog-secureheal-trainer.hf.space`

---

## GET /health

Returns the current health status of the Space and whether the model is loaded.

**Request:**
```
GET /health
```

**Response (200):**
```json
{
  "status": "healthy",
  "model_loaded": true,
  "model": "Nitesh-Reddy/secureheal-agent-v2"
}
```

**When to use:** Call this before any scan request to confirm the Space is awake and the model is ready. If `model_loaded` is `false`, wait 1-2 minutes and retry.

---

## POST /scan

Scans a code snippet provided as a JSON body. Runs the full 3-agent debate pipeline (Alpha scanner, Beta attacker, Gamma defender) and returns the combined analysis along with any tool calls the agents produced.

**Request:**
```
POST /scan
Content-Type: application/json
```

**Body:**
| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `code` | string | Yes | - | The source code to analyze |
| `context` | string | No | `"web application"` | Describes the application type (e.g. "flask api", "express server") |
| `max_tokens` | integer | No | `512` | Maximum tokens for the model response |

**Example:**
```json
{
  "code": "cursor.execute(f\"SELECT * FROM users WHERE id = {user_id}\")",
  "context": "flask api",
  "max_tokens": 512
}
```

**Response (200):**
```json
{
  "vulnerabilities_found": true,
  "tool_calls": [
    { "tool": "scan_code", "args": {} },
    { "tool": "simulate_attack", "args": { "payload": "1 OR 1=1" } },
    { "tool": "apply_patch", "args": { "patch_code": "cursor.execute(\"SELECT * FROM users WHERE id = ?\", (user_id,))" } }
  ],
  "analysis": "[AGENT ALPHA - RECON SCANNER]\n..."
}
```

**Error Codes:**
- `503` - Model is still loading. Retry after a short wait.

---

## POST /scan/file

Uploads a source code file for vulnerability scanning. This is what the SecureHeal CLI (`secureheal_cli.py`) calls under the hood. Supports `.py`, `.js`, `.ts`, `.java`, `.go`, `.rb`, `.php`, and more.

**Request:**
```
POST /scan/file
Content-Type: multipart/form-data
```

**Fields:**
| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `file` | file (binary) | Yes | - | The source code file to scan |
| `context` | string (form) | No | `"web application"` | Application type hint |
| `max_tokens` | integer (form) | No | `512` | Maximum tokens for the model response |

**Example (curl):**
```bash
curl -X POST https://ravindraog-secureheal-trainer.hf.space/scan/file \
  -F "file=@vulnerable_app.py" \
  -F "context=flask api" \
  -F "max_tokens=512"
```

**Response (200):**
```json
{
  "vulnerabilities_found": true,
  "tool_calls": [ ... ],
  "analysis": "...",
  "filename": "vulnerable_app.py"
}
```

**Notes:**
- Files larger than 8000 characters are automatically truncated to fit the model context window.
- The `filename` field in the response echoes back the uploaded file name.

**Error Codes:**
- `400` - File is not a valid text/source code file.
- `503` - Model is still loading.

---

## POST /agent

A free-form prompt endpoint. Send any text prompt to the SecureHeal agent and get back a raw response along with any parsed tool calls. This is useful for custom queries outside the standard scan workflow.

**Request:**
```
POST /agent
Content-Type: application/json
```

**Body:**
| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `prompt` | string | Yes | - | Free-form text prompt for the agent |
| `max_tokens` | integer | No | `512` | Maximum tokens for the response |

**Example:**
```json
{
  "prompt": "Explain the OWASP Top 10 vulnerability categories and which ones apply to Python Flask apps.",
  "max_tokens": 256
}
```

**Response (200):**
```json
{
  "response": "The OWASP Top 10 covers...",
  "tool_calls": []
}
```

**Error Codes:**
- `503` - Model is still loading.

---

## GET / (Gradio Dashboard)

The root path serves the **VS Code-style Gradio IDE Dashboard**. This is the visual interface that judges and users see when they visit the Hugging Face Space directly. It is mounted as a Gradio app on top of the FastAPI backend.

**URL:** `https://ravindraog-secureheal-trainer.hf.space/`

This is not an API endpoint in the traditional sense. It renders the interactive web UI.

---

## Data Models

### VulnerabilityReport

Returned by `/scan` and `/scan/file`.

| Field | Type | Description |
|-------|------|-------------|
| `vulnerabilities_found` | boolean | Whether the agent detected any issues |
| `tool_calls` | array of ToolCall | Parsed tool calls from the agent output |
| `analysis` | string | Full text of the multi-agent debate log |
| `filename` | string or null | Original filename (only for `/scan/file`) |

### ToolCall

| Field | Type | Description |
|-------|------|-------------|
| `tool` | string | Name of the tool called (e.g. `scan_code`, `apply_patch`) |
| `args` | object | Arguments passed to the tool |

### AgentResponse

Returned by `/agent`.

| Field | Type | Description |
|-------|------|-------------|
| `response` | string | The agent's text response |
| `tool_calls` | array of ToolCall | Any tool calls parsed from the response |

---

## Rate Limits and Constraints

- The Hugging Face Space runs on a **T4 GPU** with limited concurrency.
- Each scan triggers three sequential model inferences (Alpha, Beta, Gamma), so expect response times of 30 to 90 seconds depending on code length.
- Files over 8000 characters are truncated.
- If the Space has been idle for a while, the first request will take longer because the model needs to load into GPU memory.

---

## Related Documentation

For a complete overview of the SecureHeal Arena project, please refer to:

- [README.md](README.md) - Project overview, architecture, and quick start guide.
- [TRAINING_EVIDENCE.md](TRAINING_EVIDENCE.md) - Training curves, reward architecture, and performance benchmarks.
- [project_context.md](project_context.md) - Detailed hackathon strategy and execution plan.
- [hf_blog_post.md](hf_blog_post.md) - Short blog post explaining the project.
- [secureheal_cli.py](secureheal_cli.py) - CLI source code that calls these endpoints.
- [training/train_hf_job.py](training/train_hf_job.py) - GRPO training script.

---
*Prepared for the Meta PyTorch OpenEnv Hackathon India 2026 by team codeXcreators.*