diff --git a/euclid/database/database.py b/euclid/database/database.py index a440c2f..3aac3e2 100644 --- a/euclid/database/database.py +++ b/euclid/database/database.py @@ -255,6 +255,17 @@ def get_development_step_from_hash_id(app_id, prompt_path, prompt_data, llm_req_ return None return dev_step +def delete_all_subsequent_steps(project): + delete_subsequent_steps(DevelopmentSteps, project.checkpoints['last_development_step'], 'previous_dev_step') + delete_subsequent_steps(CommandRuns, project.checkpoints['last_command_run'], 'previous_command_run') + delete_subsequent_steps(UserInputs, project.checkpoints['last_user_input'], 'previous_user_input') + +def delete_subsequent_steps(model, step, step_field_name): + print(colored(f"Deleting subsequent {model.__name__} steps after {step.id}", "red")) + subsequent_step = model.get_or_none(**{step_field_name: step.id}) + if subsequent_step: + delete_subsequent_steps(model, subsequent_step, step_field_name) + subsequent_step.delete_instance() def create_tables(): with database: diff --git a/euclid/helpers/AgentConvo.py b/euclid/helpers/AgentConvo.py index 962f9ba..ddb49f7 100644 --- a/euclid/helpers/AgentConvo.py +++ b/euclid/helpers/AgentConvo.py @@ -1,7 +1,7 @@ import subprocess from termcolor import colored -from database.database import get_development_step_from_hash_id, save_development_step +from database.database import get_development_step_from_hash_id, save_development_step, delete_all_subsequent_steps from utils.utils import array_of_objects_to_string from utils.llm_connection import get_prompt, create_gpt_chat_completion from utils.utils import get_sys_message, find_role_from_step, capitalize_first_word_with_underscores @@ -35,6 +35,7 @@ class AgentConvo: # if we do, use it if self.agent.project.skip_until_dev_step and str(development_step.id) == self.agent.project.skip_until_dev_step: self.agent.project.skip_steps = False + delete_all_subsequent_steps(self.agent.project) print(colored(f'Restoring development step with id {development_step.id}', 'yellow')) self.agent.project.checkpoints['last_development_step'] = development_step self.agent.project.restore_files(development_step.id)