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

Code before:

            if response['user_input'] == 'continue':
                response['success'] = True
            else:
                response['success'] = self.debugger.debug(convo,
                                                   user_input=response['user_input'],
                                                   issue_description=step['human_intervention_description'])
                # TODO add review

            return response

    def step_test(self, convo, test_command):
        # TODO: don't re-run if it's already running
        should_rerun_command = convo.send_message('dev_ops/should_rerun_command.prompt', test_command)
        if should_rerun_command == 'NO':
            return { 'success': True }
        elif should_rerun_command == 'YES':
            logger.info('Re-running test command: %s', test_command)
            cli_response, llm_response = execute_command_and_check_cli_response(convo, test_command)
            logger.info('After running command llm_response: ' + llm_response)
            if llm_response == 'NEEDS_DEBUGGING':
                print(color_red('Got incorrect CLI response:'))
                print(cli_response)
                print(color_red('-------------------'))

            result = {'success': llm_response == 'DONE' or llm_response == 'SKIP', 'cli_response': cli_response}
            if cli_response is None:
                result['user_input'] = llm_response
            else:
                result['llm_response'] = llm_response
            return result

    def get_run_command(self, convo):
        llm_response = convo.send_message('development/get_run_command.prompt', {}, COMMAND_TO_RUN)
        self.run_command = llm_response['command']

        # Pattern for triple backtick code block with optional language
        triple_backtick_pattern = r"```(?:\w+\n)?(.*?)```"
        triple_match = re.search(triple_backtick_pattern, self.run_command, re.DOTALL)
        # Pattern for single backtick
        single_backtick_pattern = r"`(.*?)`"
        single_match = re.search(single_backtick_pattern, self.run_command, re.DOTALL)

        if triple_match:
            self.run_command = triple_match.group(1).strip()
        elif single_match:
            self.run_command = single_match.group(1).strip()

    def task_postprocessing(self, convo, development_task, continue_development, task_result, last_branch_name):
        # TODO: why does `run_command` belong to the Developer class, rather than just being passed?
        #       ...It's set by execute_task() -> task_postprocessing(), but that is called by various sources.

Review comment (suggestion):
Nitpick: in these cases I like to use `llm_response in ["DONE", "SKIP"]`, looks a bit easier to read.

Also, whenever the items are not just `name: variable` (like  here, there's some logic), for readability I'd recommend having it in a few lines, at least to me this looks easier to parse:

```
result = {
    "success": ...,
    "cli_response": ...,
}
```

Code after:

            if response['user_input'] == 'continue':
                response['success'] = True
            else:
                response['success'] = self.debugger.debug(convo,
                                                   user_input=response['user_input'],
                                                   issue_description=step['human_intervention_description'])
                # TODO add review

            return response

    def step_test(self, convo, test_command):
        # TODO: don't re-run if it's already running
        should_rerun_command = convo.send_message('dev_ops/should_rerun_command.prompt', test_command)
        if should_rerun_command == 'NO':
            return { 'success': True }
        elif should_rerun_command == 'YES':
            logger.info('Re-running test command: %s', test_command)
            cli_response, llm_response = execute_command_and_check_cli_response(convo, test_command)
            logger.info('After running command llm_response: ' + llm_response)
            if llm_response == 'NEEDS_DEBUGGING':
                print(color_red('Got incorrect CLI response:'))
                print(cli_response)
                print(color_red('-------------------'))

            result = {
                'success': llm_response in ["DONE", "SKIP"],
                'cli_response': cli_response
            }
            if cli_response is None:
                result['user_input'] = llm_response
            else:
                result['llm_response'] = llm_response
            return result

    def get_run_command(self, convo):
        llm_response = convo.send_message('development/get_run_command.prompt', {}, COMMAND_TO_RUN)
        self.run_command = llm_response['command']

        # Pattern for triple backtick code block with optional language
        triple_backtick_pattern = r"```(?:\w+\n)?(.*?)```"
        triple_match = re.search(triple_backtick_pattern, self.run_command, re.DOTALL)
        # Pattern for single backtick
        single_backtick_pattern = r"`(.*?)`"
        single_match = re.search(single_backtick_pattern, self.run_command, re.DOTALL)

        if triple_match:
            self.run_command = triple_match.group(1).strip()
        elif single_match:
            self.run_command = single_match.group(1).strip()