Repository: ErikBjare/gptme
File: gptme/util/ask_execute.py (Python)

Code before:
    choicestr += "]"

    session = get_prompt_session()
    answer = (
        session.prompt(
            [("bold fg:ansiyellow bg:red", f" {question} {choicestr} "), ("", " ")],
        )
        .lower()
        .strip()
    )

    if not override_auto:
        if copiable and answer == "c":
            if copy():
                print("Copied to clipboard.")
                return False
            clear_copiable()
        elif editable and answer == "e":
            edited = edit_text_with_editor(get_editable_text(), ext=get_editable_ext())
            if edited != get_editable_text():
                set_edited_text(edited)
                print("Content updated.")
                return ask_execute("Execute with changes?", default)
            return False

    # secret option to skip asking for a number of times
    match = pattern.match(answer)
    if match:
        if match.group(2):
            auto_skip_count = int(match.group(2))
            return True
        if match.group(1):
            return (override_auto := True)

    # secret option to ask for help
    if answer in ["help", "h", "?"]:
        lines = [
            "Options:",
            " y - execute the code",
            " n - do not execute the code",
        ]
        if copiable:
            lines.append(" c - copy the code to the clipboard")
        if editable:
            lines.append(" e - edit the code before executing")
        lines.extend(
            [
                " auto - stop asking for the rest of the session",
                f"Default is '{'y' if default else 'n'}' if answer is empty.",
            ]
        )

Review comment (security):
Not so secret anymore
```suggestion
    # skip asking for a number of times
```

Code after:
    answer = (
        session.prompt(
            [("bold fg:ansiyellow bg:red", f" {question} {choicestr} "), ("", " ")],
        )
        .lower()
        .strip()
    )

    if not override_auto:
        if copiable and answer == "c":
            if copy():
                print("Copied to clipboard.")
                return False
            clear_copiable()
        elif editable and answer == "e":
            edited = edit_text_with_editor(get_editable_text(), ext=get_editable_ext())
            if edited != get_editable_text():
                set_edited_text(edited)
                print("Content updated.")
                return ask_execute("Execute with changes?", default)
            return False

    re_auto = r"auto(?:\s+(\d+))?"
    match = re.match(re_auto, answer)
    if match:
        if match.group(2):
            auto_skip_count = int(match.group(2))
            return True
        else:
            return (override_auto := True)

    # secret option to ask for help
    if answer in ["help", "h", "?"]:
        lines = [
            "Options:",
            " y - execute the code",
            " n - do not execute the code",
        ]
        if copiable:
            lines.append(" c - copy the code to the clipboard")
        if editable:
            lines.append(" e - edit the code before executing")
        lines.extend(
            [
                " auto - stop asking for the rest of the session",
                f"Default is '{'y' if default else 'n'}' if answer is empty.",
            ]
        )
        helptext = "\n".join(lines)
        print(helptext)
        return ask_execute(question, default)