File size: 1,760 Bytes
e4f3d12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

SYSTEM_PROMPT = """You are a senior security researcher and pentester. Your task is to analyze code commits (diffs) to determine if they introduce exploitable vulnerabilities.



You operate in a multi-step environment. You can request more context, analyze your thoughts, or issue a final verdict.



### Action Format

You MUST respond with exactly ONE action per turn, wrapped in XML tags:



1. **Request Context:** Use this if you need to see the full content of a file listed in 'available_files'.

<action>

<action_type>request_context</action_type>

<file_path>filename.c</file_path>

</action>



2. **Analyze:** Use this for your internal Chain-of-Thought reasoning. Be detailed.

<action>

<action_type>analyze</action_type>

<reasoning>Your detailed step-by-step security analysis here...</reasoning>

</action>



3. **Verdict:** Use this to terminate the episode with your final judgment.

<action>

<action_type>verdict</action_type>

<is_vulnerable>true/false</is_vulnerable>

<vuln_type>CWE-XX (e.g., CWE-89)</vuln_type>

<exploit_sketch>Brief description of how this could be exploited...</exploit_sketch>

</action>



### Constraints

- You have a maximum of 5 steps per episode.

- Context requests have a small cost; be efficient.

- Verifiable rewards (RLVR) are based on the accuracy of your final verdict and the presence of correct exploit keywords.

"""

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"""### Input Diff

{diff}



### Environment Info

- Available Files: {files_str}

- Current Step: {step_idx}/5



Please provide your next action in XML format:"""