44from dataclasses import dataclass
55from mako .template import Template
66from hackingBuddyGPT .capability import capabilities_to_simple_text_handler
7- from hackingBuddyGPT .usecases .base import UseCase
7+ from hackingBuddyGPT .usecases .usecase import UseCase
88from hackingBuddyGPT .utils import llm_util
99from hackingBuddyGPT .utils .histories import HistoryCmdOnly , HistoryFull , HistoryNone
10+ from hackingBuddyGPT .utils .openai .openai_lib import OpenAILib
1011from hackingBuddyGPT .utils .openai .openai_llm import OpenAIConnection
1112from hackingBuddyGPT .utils .logging import log_conversation , Logger , log_param , log_section
1213from hackingBuddyGPT .utils .capability_manager import CapabilityManager
@@ -140,3 +141,59 @@ def check_success(self, cmd:str, result:str) -> bool:
140141
141142 def postprocess_commands (self , cmd :str ) -> List [str ]:
142143 return [cmd ]
144+
145+ @dataclass
146+ class SimpleStrategy (UseCase , abc .ABC ):
147+ max_turns : int = 10
148+
149+ llm : OpenAILib = None
150+
151+ log : Logger = log_param
152+
153+ _got_root : bool = False
154+
155+ _capabilities : CapabilityManager = None
156+
157+ def init (self ):
158+ super ().init ()
159+ self ._capabilities = CapabilityManager (self .log )
160+
161+ @abc .abstractmethod
162+ def perform_round (self , turn : int ):
163+ pass
164+
165+ def before_run (self ):
166+ pass
167+
168+ def after_run (self ):
169+ pass
170+
171+ def run (self , configuration ):
172+ self .configuration = configuration
173+ self .log .start_run (self .get_name (), self .serialize_configuration (configuration ))
174+
175+ self .before_run ()
176+
177+ turn = 1
178+ try :
179+ while turn <= self .max_turns and not self ._got_root :
180+ with self .log .section (f"round { turn } " ):
181+ self .log .console .log (f"[yellow]Starting turn { turn } of { self .max_turns } " )
182+
183+ self ._got_root = self .perform_round (turn )
184+
185+ turn += 1
186+
187+ self .after_run ()
188+
189+ # write the final result to the database and console
190+ if self ._got_root :
191+ self .log .run_was_success ()
192+ else :
193+ self .log .run_was_failure ("maximum turn number reached" )
194+
195+ return self ._got_root
196+ except Exception :
197+ import traceback
198+ self .log .run_was_failure ("exception occurred" , details = f":\n \n { traceback .format_exc ()} " )
199+ raise
0 commit comments