Repository: Pythagora-io/gpt-pilot
File: pilot/helpers/agents/Developer.py (Python)

Code before:
            'running_processes': running_processes,
            'os': platform.system(),
        }, IMPLEMENT_TASK)
        task_steps = response['tasks']
        convo_dev_task.remove_last_x_messages(2)

        while True:
            result = self.execute_task(convo_dev_task,
                                     task_steps,
                                     development_task=development_task,
                                     continue_development=True,
                                     is_root_task=True)

            if result['success']:
                break

            if 'step_index' in result:
                result['running_processes'] = running_processes
                result['os'] = platform.system()
                step_index = result['step_index']
                result['completed_steps'] = task_steps[:step_index]
                result['current_step'] = task_steps[step_index]
                result['next_steps'] = task_steps[step_index + 1:]
                result['current_step_index'] = step_index

                convo_dev_task.remove_last_x_messages(1)
                response = convo_dev_task.send_message('development/task/update_task.prompt', result, IMPLEMENT_TASK)
                task_steps = response['tasks']

            else:
                logger.warning('Testing at end of task failed')
                break

    def step_code_change(self, convo, step, i, test_after_code_changes):
        if step['type'] == 'code_change' and 'code_change_description' in step:
            # TODO this should be refactored so it always uses the same function call
            print(f'Implementing code changes for `{step["code_change_description"]}`')
            code_monkey = CodeMonkey(self.project, self)
            updated_convo = code_monkey.implement_code_changes(convo, step['code_change_description'], i)
            if test_after_code_changes:
                return self.test_code_changes(code_monkey, updated_convo)
            else:
                return { "success": True }

        elif step['type'] == 'code_change':
            # TODO fix this - the problem is in GPT response that sometimes doesn't return the correct JSON structure
            if 'code_change' not in step:
                data = step
            else:
                data = step['code_change']
            self.project.save_file(data)

Review comment (bug):
in Debugger.py you are removing last 2 messages before calling 'update_task.prompt' and here only last one. Not sure if that is ok, please just double check.

Code after:
            'running_processes': running_processes,
            'os': platform.system(),
        }, IMPLEMENT_TASK)
        task_steps = response['tasks']
        convo_dev_task.remove_last_x_messages(2)

        while True:
            result = self.execute_task(convo_dev_task,
                                     task_steps,
                                     development_task=development_task,
                                     continue_development=True,
                                     is_root_task=True)

            if result['success']:
                break

            if 'step_index' in result:
                result['running_processes'] = running_processes
                result['os'] = platform.system()
                step_index = result['step_index']
                result['completed_steps'] = task_steps[:step_index]
                result['current_step'] = task_steps[step_index]
                result['next_steps'] = task_steps[step_index + 1:]
                result['current_step_index'] = step_index

                convo_dev_task.remove_last_x_messages(2)
                response = convo_dev_task.send_message('development/task/update_task.prompt', result, IMPLEMENT_TASK)
                task_steps = response['tasks']

            else:
                logger.warning('Testing at end of task failed')
                break

    def step_code_change(self, convo, step, i, test_after_code_changes):
        if step['type'] == 'code_change' and 'code_change_description' in step:
            # TODO this should be refactored so it always uses the same function call
            print(f'Implementing code changes for `{step["code_change_description"]}`')
            code_monkey = CodeMonkey(self.project, self)
            updated_convo = code_monkey.implement_code_changes(convo, step['code_change_description'], i)
            if test_after_code_changes:
                return self.test_code_changes(code_monkey, updated_convo)
            else:
                return { "success": True }

        elif step['type'] == 'code_change':
            # TODO fix this - the problem is in GPT response that sometimes doesn't return the correct JSON structure
            if 'code_change' not in step:
                data = step
            else:
                data = step['code_change']
            self.project.save_file(data)