Coverage for src/pullapprove/agent/__init__.py: 0%

27 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-08-05 11:07 -0500

1import shlex 

2import subprocess 

3from enum import Enum 

4from functools import cached_property 

5 

6from .shared import load_prompt 

7 

8 

9class AgentType(Enum): 

10 EDIT = "edit" 

11 NEW = "new" 

12 FIX = "fix" 

13 MIGRATE_V3 = "migrate_v3" 

14 MIGRATE_CODEOWNERS = "migrate_codeowners" 

15 

16 

17class Agent: 

18 def __init__(self, agent_type: AgentType): 

19 self.agent_type = agent_type 

20 

21 @cached_property 

22 def prompt(self): 

23 prompt = load_prompt("base") 

24 

25 prompt += "\n\n" + load_prompt(self.agent_type.value) 

26 

27 return prompt 

28 

29 def run_command(self, command: str): 

30 prompt = self.prompt 

31 prompt += "\n\n" + load_prompt("cli") 

32 

33 command_args = shlex.split(command) 

34 command_args.append(prompt) 

35 

36 result = subprocess.run(command_args) 

37 

38 return result.returncode == 0 

39 

40 

41__all__ = ["Agent", "AgentType", "load_prompt"]