File size: 1,332 Bytes
95cbc5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Standalone utility for parsing XML-tagged model actions.
Wraps the core logic in commitguard_env.
"""

import sys
import os
import json

# Ensure parent directory is in path to find commitguard_env
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from commitguard_env.models import CommitGuardAction
from commitguard_env.parse_action import parse_action as core_parse

def parse_action_to_dict(raw_text: str) -> CommitGuardAction:
    """
    Parses an XML action string and returns a CommitGuardAction object.
    Handles malformed responses gracefully.
    """
    return core_parse(raw_text)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        test_input = " ".join(sys.argv[1:])
        action = parse_action_to_dict(test_input)
        # Convert to dict for printing
        res = {
            "action_type": action.action_type,
            "file_path": action.file_path,
            "reasoning": action.reasoning,
            "is_vulnerable": action.is_vulnerable,
            "vuln_type": action.vuln_type,
            "exploit_sketch": action.exploit_sketch,
            "parse_error": action.parse_error
        }
        print(json.dumps({k: v for k, v in res.items() if v is not None}, indent=2))
    else:
        print("Usage: python parse_action.py '<action>...</action>'")