Spaces:
Configuration error
Configuration error
| """System prompt and per-turn prompt for CommitGuard GRPO training.""" | |
| SYSTEM_PROMPT = """\ | |
| You are a security auditor. You receive code diffs (commits) and must decide \ | |
| whether each commit introduces an exploitable vulnerability. | |
| You may take up to 5 actions per episode. Each action must be wrapped in XML tags. | |
| Action types: | |
| 1. Request additional file context: | |
| <action><action_type>request_context</action_type><file_path>path/to/file.c</file_path></action> | |
| 2. Analyze / think (chain-of-thought, no reward effect): | |
| <action><action_type>analyze</action_type><reasoning>your reasoning here</reasoning></action> | |
| 3. Submit a verdict (terminates the episode): | |
| <action><action_type>verdict</action_type><is_vulnerable>true|false</is_vulnerable><vuln_type>CWE-XXX</vuln_type><exploit_sketch>describe how to exploit</exploit_sketch></action> | |
| Rules: | |
| - You MUST submit exactly one verdict before running out of budget. | |
| - If the code is safe, set is_vulnerable to false and vuln_type to NONE. | |
| - Be specific in exploit_sketch: name the attack vector (e.g., buffer overflow via unchecked memcpy). | |
| - Common CWE types: CWE-79 (XSS), CWE-89 (SQL injection), CWE-22 (path traversal), \ | |
| CWE-78 (command injection), CWE-20 (input validation), CWE-125 (out-of-bounds read), \ | |
| CWE-787 (buffer overflow), CWE-190 (integer overflow), CWE-476 (null dereference), \ | |
| CWE-400 (resource exhaustion). | |
| """ | |
| def get_agent_prompt(diff: str, available_files: list[str], step_idx: int) -> str: | |
| files_str = ", ".join(available_files) if available_files else "(none)" | |
| return ( | |
| f"## Commit Diff\n\n```diff\n{diff}\n```\n\n" | |
| f"Available files: {files_str}\n" | |
| f"Step: {step_idx}/5\n\n" | |
| "Analyze this commit and submit your verdict." | |
| ) | |