# shellcheck shell=dash
___x_cmd_perl_co(){
    [ "$#" -gt 0 ] || set -- "$(___x_cmd_cmds_cat)"
    x chat --request --type co,perl --minion "$___X_CMD_ROOT_MOD/perl/lib/minion/co.yml" "$@"
}

# using the perl facility to test the code

___x_cmd_perl_coco(){
    [ "$#" -gt 0 ] || set -- "$(___x_cmd_cmds_cat)"

    local code=

    # Consider refine the code ...
    code=$(x chat -n 0 --request --type coco,perl --minion "$___X_CMD_ROOT_MOD/perl/lib/minion/coco.yml" "$@")

    local feedback=
    feedback=$(printf "%s\n" "$code" | x perl -c) || {
        {
            printf "Linting fail. Here is the feedback:"
            printf "%s\n" "$feedback"
        } >/dev/tty

        while true; do
            x ui select "" "what's next" "Send feedback to ai for better answer" "view the feed back and code" "Exit" || {
                co:error "Recv interrupts. Exit"
                return 130
            }
            case "$___X_CMD_UI_SELECT_RET" in
                1)
                    # x chat -n 0 --request coco,perl "$feedback" "$msg"
                    #
                    x:error "Unsuported"
                    return 1
                    ;;
                2)  printf "%s\n" "$code" | x bat -l perl ;;
                3)  return 1 ;;
            esac
        done
    }

    printf "%s\n" "$code" | x bat -l perl
    x ui yesno "Do you want to run the code" || return 0        # default is no.

    printf "%s\n" "$code" | x perl
}
