def _monkey_patch_cleo(self, prefix: str, task_names: list[str]):
        """
        Cleo is quite opinionated about CLI structure and loose about how options are
        used, and so doesn't currently support individual commands having their own way
        of interpreting arguments, and forces them to inherit certain options from the
        application. This is a problem for poe which requires that global options are
        provided before the task name, and everything after the task name is interpreted
        ONLY in terms of the task.

        This hack monkey-patches internals of Cleo that are invoked directly after
        plugin's are loaded by poetry, and exploits a feature whereby argument and
        option parsing are effectively disabled following any occurrence of a "--" on
        the command line, but parsing of the command name still works! Thus the solution
        is to detect when it is a command from this plugin that is about to be executed
        and insert the "--" token at the start of the tokens list of the ArgvInput
        instance that the application is about to read the CLI options from.

        Hopefully this doesn't get broken by a future update to poetry or cleo :S
        """

        import cleo.application

        continue_run = cleo.application.Application._run

        def _run(self, io):
            # Trick cleo to ignoring arguments and options following one of the commands
            # from this plugin by injecting a '--' token at the start of the list of
            # command line tokens
            tokens = io.input._tokens
            task_name_index = _index_of_first_non_option(tokens)
            poe_commands = (prefix,) if prefix else task_names
            if (
                0 <= task_name_index < len(tokens)
                and tokens[task_name_index] in poe_commands
            ):
                # update tokens list in place
                tokens.insert(task_name_index, "--")

            return continue_run(self, io)

        # Apply the patch
        cleo.application.Application._run = _run

        Cleo is quite opinionated about CLI structure and loose about how options are
        used, and so doesn't currently support individual commands having their own way
        of interpreting arguments, and forces them to inherit certain options from the
        application. This is a problem for poe which requires that global options are
        provided before the task name, and everything after the task name is interpreted
        ONLY in terms of the task.

        This hack monkey-patches internals of Cleo that are invoked directly after
        plugin's are loaded by poetry, and exploits a feature whereby argument and
        option parsing are effectively disabled following any occurrence of a "--" on
        the command line, but parsing of the command name still works! Thus the solution
        is to detect when it is a command from this plugin that is about to be executed
        and insert the "--" token at the start of the tokens list of the ArgvInput
        instance that the application is about to read the CLI options from.

        Hopefully this doesn't get broken by a future update to poetry or cleo :S
        
poethepoet/plugin.py