# shellcheck shell=dash

___x_cmd_python_co(){
    [ "$#" -gt 0 ] || set -- "$(___x_cmd_cmds_cat)"
    # Consider refine the code ...
    ___x_cmd chat --request --type co,python --minion "$___X_CMD_ROOT_MOD/python/lib/minion/co.yml" "$@"
}

# using the python facility to test the code 

___x_cmd_python_coco(){
    [ "$#" -gt 0 ] || set -- "$(___x_cmd_cmds_cat)"
    local code=
    # Consider refine the code ...
    code=$(___x_cmd chat --request --type coco,python --minion "$___X_CMD_ROOT_MOD/python/lib/minion/coco.yml" "$@")
    local feedback=
    feedback=$(printf "%s\n" "$code" | ___x_cmd python --compile-pipe) || {
        {
            printf "Linting fail. Here is the feedback:"
            printf "%s\n" "$feedback" 
        } >/dev/tty
        
        while true; do
            ___x_cmd 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_cmd chat -n 0 --request coco,python "$feedback" "$msg"
                    # 
                    python:error "Unsuported"
                    return 1
                    ;;
                2)  printf "%s\n" "$code" | ___x_cmd bat -l python ;;
                3)  return 1 ;;
            esac
        done
    }

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

    printf "%s\n" "$code" | ___x_cmd python
}
