kanishcr7 commited on
Commit
97f7a40
·
2 Parent(s): b70c5b905e09d6

Merge resolved

Browse files
Files changed (1) hide show
  1. README.md +229 -19
README.md CHANGED
@@ -1,15 +1,12 @@
1
- ---
2
- title: PatchHawk
3
- emoji: 🦅
4
- colorFrom: gray
5
- colorTo: yellow
6
- sdk: docker
7
- app_port: 7860
8
- pinned: false
9
- ---
10
 
11
- # 🦅 PatchHawk: Autonomous Supply-Chain Guard
 
 
 
 
12
 
 
13
  [![Weights & Biases](https://img.shields.io/badge/Weights%20%26%20Biases-FFBE00?logo=weightsandbiases&logoColor=black)](https://wandb.ai)
14
  [![Hugging Face](https://img.shields.io/badge/Hugging%20Face-FFD21E?logo=huggingface&logoColor=black)](https://huggingface.co)
15
  [![Python 3.12](https://img.shields.io/badge/Python-3.12-blue?logo=python&logoColor=white)](https://python.org)
@@ -59,9 +56,87 @@ The agent learns to produce patches that not only compile but also withstand re
59
  ---
60
 
61
  ## 🛠️ Project Structure
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- ```text
 
 
 
 
 
 
 
 
 
 
64
  PatchHawk/
 
65
  ├── src/envs/patchhawk/ # 📦 OpenEnv Submission Package
66
  │ ├── server/ # FastAPI environment server
67
  │ ├── models.py # Type‑safe contract definitions
@@ -75,58 +150,106 @@ PatchHawk/
75
  ├── config.yaml # Environment & Agent configuration
76
  ├── openenv.yaml # OpenEnv metadata
77
  ├── .env.example # Environment variable template
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  └── README.md
79
  ```
80
 
81
  ---
82
 
83
- ## 🚀 Getting Started
84
 
85
  ### Prerequisites
86
 
 
87
  - Python 3.12 or higher
88
  - Docker Engine (running locally, with buildx available)
89
  - NVIDIA GPU (8 GB VRAM or more recommended for training and inference)
90
  - Hugging Face account and token (for model access)
 
 
 
 
 
 
91
 
92
- ### 1. Installation
 
 
93
 
94
  ```bash
95
- # Clone the repository
96
  git clone https://github.com/ramprasathk07/PatchHawk.git
97
  cd PatchHawk
98
 
 
99
  # Create and activate a virtual environment
100
  python -m venv .venv
101
  source .venv/bin/activate # On Windows: .venv\Scripts\activate
102
 
103
  # Install core dependencies
 
 
 
 
 
104
  pip install -e .
105
  ```
106
 
107
- ### 2. Environment Setup
108
 
109
  ```bash
 
110
  # Copy the environment template and populate your keys
111
  cp .env.example .env
112
  # Edit .env to include HF_TOKEN, OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.
113
 
114
  # Build the validation sandbox Docker image
 
 
 
 
 
115
  docker build -t patchhawk-sandbox:latest -f docker/Dockerfile.sandbox .
116
  ```
117
 
118
- ### 3. Running the Agent (Dry Run)
 
 
119
 
120
  ```bash
 
121
  # Start the environment server (in one terminal)
122
  python -m server.app --port 8000
123
 
124
  # Execute the inference loop (in another terminal)
 
 
 
 
 
 
125
  python src/envs/patchhawk/inference.py --env-url http://localhost:8000
126
  ```
127
 
128
  ---
129
 
 
130
  ## 💎 Reward Rubric
131
 
132
  The agent is guided by a granular reward structure that encourages safe, effective, and verifiable actions.
@@ -142,17 +265,72 @@ The agent is guided by a granular reward structure that encourages safe, effecti
142
  ### Dynamic Scaling Factors
143
  - **Risk Accuracy Bonus**: Up to `+2.0` additional reward for accurately predicting the risk score of a vulnerability.
144
  - **Safety Multiplier**: Repeated syntax check failures apply a decay factor to all future rewards.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
  ---
147
 
148
- ## 📈 Dashboard & UI
149
 
 
150
  Launch the **Security Operations Center (SOC)** dashboard to observe the agent's reasoning in real time.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
  ```bash
153
  streamlit run patchhawk/app/dashboard.py
154
  ```
155
 
 
156
  The dashboard provides:
157
  - Live XML reasoning logs from the agent.
158
  - Real‑time stdout/stderr streams from the Docker sandbox.
@@ -173,11 +351,43 @@ The dashboard provides:
173
  - [ ] **Automated PR Remediation**: Generate and submit fix‑containing pull requests for detected vulnerabilities.
174
  - [ ] **Adversarial Training Loop**: Implement a self‑improving LLM‑vs‑LLM red‑team / blue‑team training regimen.
175
  - [ ] **Supply‑Chain Malware Detection**: Extend dependency analysis to identify novel, unpublished attack patterns.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  ---
178
 
179
- ## 📝 License
180
 
 
181
  Distributed under the **MIT License**. See the LICENSE file in the repository root for full details.
182
 
183
- Developed with ❤️ by **Ramprasath K & The PatchHawk Team** for the OpenEnv Hackathon 2026 hosted by Meta.
 
 
 
 
 
 
1
+ # PatchHawk
 
 
 
 
 
 
 
 
2
 
3
+ [![Weights & Biases](https://img.shields.io/badge/Weights%20%26%20Biases-FFBE00?logo=weightsandbiases&logoColor=black)](https://wandb.ai)
4
+ [![Hugging Face](https://img.shields.io/badge/Hugging%20Face-FFD21E?logo=huggingface&logoColor=black)](https://huggingface.co)
5
+ [![Python 3.12](https://img.shields.io/badge/Python-3.12-blue?logo=python&logoColor=white)](https://python.org)
6
+ [![OpenEnv](https://img.shields.io/badge/OpenEnv-Compliant-2ea44f)](https://openenv.dev)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
 
9
+ <<<<<<< HEAD
10
  [![Weights & Biases](https://img.shields.io/badge/Weights%20%26%20Biases-FFBE00?logo=weightsandbiases&logoColor=black)](https://wandb.ai)
11
  [![Hugging Face](https://img.shields.io/badge/Hugging%20Face-FFD21E?logo=huggingface&logoColor=black)](https://huggingface.co)
12
  [![Python 3.12](https://img.shields.io/badge/Python-3.12-blue?logo=python&logoColor=white)](https://python.org)
 
56
  ---
57
 
58
  ## 🛠️ Project Structure
59
+ =======
60
+ **Submitted to the OpenEnv Hackathon 2026 — hosted by Meta.**
61
+
62
+ PatchHawk is an autonomous DevSecOps agent trained with Group Relative Policy Optimization (GRPO). It moves beyond static vulnerability detection by validating findings inside isolated Docker sandboxes and generating syntactically correct, re-attack-verified patches. The system closes the loop between detection, validation, and remediation through a reinforcement learning feedback cycle grounded in real execution environments.
63
+
64
+ ---
65
+
66
+ ## Table of Contents
67
+
68
+ - [Architecture Overview](#architecture-overview)
69
+ - [Key Capabilities](#key-capabilities)
70
+ - [Project Structure](#project-structure)
71
+ - [Getting Started](#getting-started)
72
+ - [Prerequisites](#prerequisites)
73
+ - [Installation](#installation)
74
+ - [Environment Setup](#environment-setup)
75
+ - [Running the Agent](#running-the-agent)
76
+ - [Training](#training)
77
+ - [Reward Rubric](#reward-rubric)
78
+ - [Dashboard](#dashboard)
79
+ - [Roadmap](#roadmap)
80
+ - [License](#license)
81
+
82
+ ---
83
+
84
+ ## Architecture Overview
85
+
86
+ Traditional security scanners suffer from high false-positive rates and produce findings that are often unexploitable or unfixable in practice. PatchHawk addresses this through a reinforcement learning loop in which the agent's reward is tied directly to the outcome of its patches inside a live execution environment.
87
+
88
+ ```
89
+ Source Code / PR
90
+ |
91
+ v
92
+ PatchHawk Agent
93
+ / | \
94
+ Analyze Test Patch
95
+ | |
96
+ Docker Verification
97
+ Sandbox Pipeline
98
+ | |
99
+ Behavioral Syntax Check
100
+ Telemetry Unit Tests
101
+ | Re-Attack
102
+ \ /
103
+ Reward Signal
104
+ |
105
+ Model Update
106
+ ```
107
+
108
+ The agent learns to produce patches that not only compile but also withstand re-execution of the original exploit vector. Every decision is accompanied by a structured `<thought>` block, providing a complete and machine-readable audit trail.
109
+
110
+ ---
111
+
112
+ ## Key Capabilities
113
+
114
+ **Autonomous Detection**
115
+ Comprehensive supply-chain analysis targeting typosquatting, backdoors, data exfiltration payloads, and malicious dependency logic.
116
+ >>>>>>> 05e09d6e3aa6dfea454f54a20062bd90863a8b86
117
+
118
+ **Hardened Sandboxing**
119
+ Docker-based isolation with network-disabled execution, strict resource caps, and ephemeral file systems for safe detonation of suspicious packages.
120
+
121
+ **GRPO-Driven Learning**
122
+ Group Relative Policy Optimization, drawing from the DeepSeek-R1 methodology, enables structured trial-and-error mastery without requiring a separate critic model.
123
+
124
+ **Structured Reasoning Traces**
125
+ All agent actions are accompanied by a `<thought>...</thought>` XML block logged for full decision auditability.
126
 
127
+ **SOC Dashboard**
128
+ Real-time Streamlit interface displaying agent reasoning, sandbox telemetry, and reward breakdowns by action type.
129
+
130
+ **OpenEnv Compliance**
131
+ Fully integrated with the PyTorch OpenEnv framework, ensuring reproducible and shareable reinforcement learning environments.
132
+
133
+ ---
134
+
135
+ ## Project Structure
136
+
137
+ ```
138
  PatchHawk/
139
+ <<<<<<< HEAD
140
  ├── src/envs/patchhawk/ # 📦 OpenEnv Submission Package
141
  │ ├── server/ # FastAPI environment server
142
  │ ├── models.py # Type‑safe contract definitions
 
150
  ├── config.yaml # Environment & Agent configuration
151
  ├── openenv.yaml # OpenEnv metadata
152
  ├── .env.example # Environment variable template
153
+ =======
154
+ ├── src/
155
+ │ └── envs/
156
+ │ └── patchhawk/
157
+ │ ├── server/ # FastAPI environment server
158
+ │ ├── models.py # Type-safe contract definitions
159
+ │ ├── client.py # Environment interaction client
160
+ │ └── inference.py # Agent execution loop
161
+ ├── patchhawk/
162
+ │ ├── data/ # Scenario generation and datasets
163
+ │ ├── training/ # GRPO training scripts
164
+ │ └── app/ # Streamlit SOC Dashboard
165
+ ├── docker/
166
+ │ └── Dockerfile.sandbox # Sandbox container configuration
167
+ ├── config.yaml # Environment and agent configuration
168
+ ├── openenv.yaml # OpenEnv metadata
169
+ ├── .env.example # Environment variable template
170
+ >>>>>>> 05e09d6e3aa6dfea454f54a20062bd90863a8b86
171
  └── README.md
172
  ```
173
 
174
  ---
175
 
176
+ ## Getting Started
177
 
178
  ### Prerequisites
179
 
180
+ <<<<<<< HEAD
181
  - Python 3.12 or higher
182
  - Docker Engine (running locally, with buildx available)
183
  - NVIDIA GPU (8 GB VRAM or more recommended for training and inference)
184
  - Hugging Face account and token (for model access)
185
+ =======
186
+ - Python 3.12 or higher
187
+ - Docker Engine with buildx support
188
+ - NVIDIA GPU with 8 GB VRAM or more (required for training; recommended for inference)
189
+ - Hugging Face account and access token
190
+ >>>>>>> 05e09d6e3aa6dfea454f54a20062bd90863a8b86
191
 
192
+ ### Installation
193
+
194
+ Clone the repository and install dependencies into a virtual environment.
195
 
196
  ```bash
 
197
  git clone https://github.com/ramprasathk07/PatchHawk.git
198
  cd PatchHawk
199
 
200
+ <<<<<<< HEAD
201
  # Create and activate a virtual environment
202
  python -m venv .venv
203
  source .venv/bin/activate # On Windows: .venv\Scripts\activate
204
 
205
  # Install core dependencies
206
+ =======
207
+ python -m venv .venv
208
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
209
+
210
+ >>>>>>> 05e09d6e3aa6dfea454f54a20062bd90863a8b86
211
  pip install -e .
212
  ```
213
 
214
+ ### Environment Setup
215
 
216
  ```bash
217
+ <<<<<<< HEAD
218
  # Copy the environment template and populate your keys
219
  cp .env.example .env
220
  # Edit .env to include HF_TOKEN, OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.
221
 
222
  # Build the validation sandbox Docker image
223
+ =======
224
+ cp .env.example .env
225
+ # Populate .env with HF_TOKEN, OPENAI_API_KEY, WANDB_API_KEY, and any other required keys.
226
+
227
+ >>>>>>> 05e09d6e3aa6dfea454f54a20062bd90863a8b86
228
  docker build -t patchhawk-sandbox:latest -f docker/Dockerfile.sandbox .
229
  ```
230
 
231
+ ### Running the Agent
232
+
233
+ Start the environment server and the inference loop in separate terminal sessions.
234
 
235
  ```bash
236
+ <<<<<<< HEAD
237
  # Start the environment server (in one terminal)
238
  python -m server.app --port 8000
239
 
240
  # Execute the inference loop (in another terminal)
241
+ =======
242
+ # Terminal 1 — environment server
243
+ python -m server.app --port 8000
244
+
245
+ # Terminal 2 — inference loop
246
+ >>>>>>> 05e09d6e3aa6dfea454f54a20062bd90863a8b86
247
  python src/envs/patchhawk/inference.py --env-url http://localhost:8000
248
  ```
249
 
250
  ---
251
 
252
+ <<<<<<< HEAD
253
  ## 💎 Reward Rubric
254
 
255
  The agent is guided by a granular reward structure that encourages safe, effective, and verifiable actions.
 
265
  ### Dynamic Scaling Factors
266
  - **Risk Accuracy Bonus**: Up to `+2.0` additional reward for accurately predicting the risk score of a vulnerability.
267
  - **Safety Multiplier**: Repeated syntax check failures apply a decay factor to all future rewards.
268
+ =======
269
+ ## Training
270
+
271
+ PatchHawk uses GRPO with a 4-bit quantised Qwen2.5-Coder-7B-Instruct base model and LoRA adapters. The training script is located at `patchhawk/training/train_grpo.py`.
272
+
273
+ **Dependencies**
274
+
275
+ ```bash
276
+ pip install trl==1.0.0 peft bitsandbytes accelerate transformers datasets wandb
277
+ ```
278
+
279
+ **Dry run (CPU, no model required)**
280
+
281
+ ```bash
282
+ python -m patchhawk.training.train_grpo --dry-run
283
+ ```
284
+
285
+ **GPU training (RTX 3060 12 GB defaults)**
286
+
287
+ ```bash
288
+ python -m patchhawk.training.train_grpo \
289
+ --epochs 3 \
290
+ --batch-size 1 \
291
+ --grad-accum 8 \
292
+ --group-size 4 \
293
+ --max-seq-len 1024 \
294
+ --output-dir grpo_lora
295
+ ```
296
+
297
+ Key training parameters and their recommended values for a 12 GB GPU are documented inline in `train_grpo.py`. To upload the trained adapter to the Hugging Face Hub, set the `HF_REPO` environment variable before running.
298
+ >>>>>>> 05e09d6e3aa6dfea454f54a20062bd90863a8b86
299
 
300
  ---
301
 
302
+ ## Reward Rubric
303
 
304
+ <<<<<<< HEAD
305
  Launch the **Security Operations Center (SOC)** dashboard to observe the agent's reasoning in real time.
306
+ =======
307
+ The agent is guided by a granular reward structure that incentivises safe, effective, and verifiable actions.
308
+
309
+ | Action ID | Action Name | Base Reward | Success Criteria |
310
+ |-----------|----------------|--------------|------------------|
311
+ | 0 | ANALYZE | 0.0 | Observation step; used for data gathering only. |
312
+ | 1 | DETONATE | +0.1 | Successful telemetry extraction from the Docker sandbox. |
313
+ | 2 | BLOCK\_PR | +2.0 / -1.0 | Positive reward for correctly blocking a malicious PR; penalty for false positives. |
314
+ | 3 | SUBMIT\_PATCH | +3.0 / -1.5 | Reward requires passing syntax check, unit tests, and re-attack validation. |
315
+ | 4 | ESCALATE | 0.0 | Defers to a human expert when uncertainty exceeds a configurable threshold. |
316
+
317
+ **Dynamic Scaling Factors**
318
+
319
+ - **Risk Accuracy Bonus.** Up to +2.0 additional reward for accurately predicting the risk score of a detected vulnerability.
320
+ - **Safety Multiplier.** Repeated syntax check failures apply a cumulative decay factor to all future rewards within a training episode.
321
+
322
+ ---
323
+
324
+ ## Dashboard
325
+
326
+ Launch the Security Operations Centre dashboard to monitor the agent in real time.
327
+ >>>>>>> 05e09d6e3aa6dfea454f54a20062bd90863a8b86
328
 
329
  ```bash
330
  streamlit run patchhawk/app/dashboard.py
331
  ```
332
 
333
+ <<<<<<< HEAD
334
  The dashboard provides:
335
  - Live XML reasoning logs from the agent.
336
  - Real‑time stdout/stderr streams from the Docker sandbox.
 
351
  - [ ] **Automated PR Remediation**: Generate and submit fix‑containing pull requests for detected vulnerabilities.
352
  - [ ] **Adversarial Training Loop**: Implement a self‑improving LLM‑vs‑LLM red‑team / blue‑team training regimen.
353
  - [ ] **Supply‑Chain Malware Detection**: Extend dependency analysis to identify novel, unpublished attack patterns.
354
+ =======
355
+ The dashboard exposes the following views:
356
+
357
+ - Live structured reasoning logs (`<thought>` traces) from the agent.
358
+ - Real-time stdout and stderr streams from the Docker sandbox.
359
+ - Detailed audit trail of reward assignments and verification outcomes per episode.
360
+
361
+ ---
362
+
363
+ ## Roadmap
364
+
365
+ The following capabilities are planned for future releases. Contributions and issue reports are welcome.
366
+
367
+ - **Multi-Agent Red-Teaming.** Deploy attacker and defender models for automated adversarial exercises.
368
+ - **CVE Ingestion.** Automatically generate training scenarios from the National Vulnerability Database.
369
+ - **Cross-Language Support.** Extend analysis beyond Python to Go, JavaScript, Rust, and Java.
370
+ - **Kubernetes Orchestration.** Scale sandbox execution using Kubernetes instead of local Docker.
371
+ - **Fine-Tuned Vulnerability Model.** Train a specialised model on vulnerability-fixing commits.
372
+ - **Code Property Graph Integration.** Apply CPG slicing for semantic vulnerability detection.
373
+ - **Silent Patch Detection.** Identify security-relevant commits that were not publicly disclosed.
374
+ - **AI-Generated Code Audit.** Trace vulnerabilities to AI coding assistants such as GitHub Copilot.
375
+ - **Automated PR Remediation.** Generate and submit fix-containing pull requests for detected issues.
376
+ - **Adversarial Self-Improvement.** Implement an LLM-vs-LLM red-team / blue-team training regimen.
377
+ - **Supply-Chain Malware Detection.** Extend dependency analysis to novel, unpublished attack patterns.
378
+ - **Dashboard Enhancements.** Add historical trend analysis, model performance metrics, and alerting.
379
+ >>>>>>> 05e09d6e3aa6dfea454f54a20062bd90863a8b86
380
 
381
  ---
382
 
383
+ ## License
384
 
385
+ <<<<<<< HEAD
386
  Distributed under the **MIT License**. See the LICENSE file in the repository root for full details.
387
 
388
+ Developed with ❤️ by **Ramprasath K & The PatchHawk Team** for the OpenEnv Hackathon 2026 hosted by Meta.
389
+ =======
390
+ Distributed under the MIT License. See `LICENSE` in the repository root for the full terms.
391
+
392
+ Developed by Ramprasath K and the PatchHawk team.
393
+ >>>>>>> 05e09d6e3aa6dfea454f54a20062bd90863a8b86