
# move chat to another session

___x_cmd_chat_session_history(){
    [ "$#" -gt 0 ]  ||  set -- ls
    local op="$1";      shift
    case "$op" in
        ls|latest|get)
            ___x_cmd_chat_session_history_"$op" "$@"
            ;;
        *)
            N=chat M="Not found [op=$op]" log:ret:64
            ;;
    esac
}

___x_cmd_chat_session_history_ls(){
    local session="${1:-"${___X_CMD_CHAT_SESSION_CURRENT}"}"
    local dir="${___X_CMD_CHAT_SESSION_DIR}/${session}"
    [ -d "$dir" ] || return 0
    ___x_cmd_cmds find "$dir" -maxdepth 1 -mindepth 1 2>/dev/null
}

___x_cmd_chat_session_history_latest(){
    local session="${1:-"${___X_CMD_CHAT_SESSION_CURRENT}"}"

    local name
    name="$(___x_cmd_cmds_ls -t "${___X_CMD_CHAT_SESSION_DIR}/${session}/" | ___x_cmd_cmds head -n 1)"
    local dir_name="${___X_CMD_CHAT_SESSION_DIR}/${session}/${name}"

    local file; while ___x_cmd_readr file; do
        printf "%s:\n  - %s\n"  "${file}" "${dir_name}/${file}"
    done <<A
$( ___x_cmd fsiter "${dir_name}" )
A

    # yml
}

# 1 2 3
___x_cmd_chat_session_history_get(){
    local history_num="${1:-3}" # Default history
    local session="${2:-"${___X_CMD_CHAT_SESSION_CURRENT}"}"
    ___x_cmd_cmds_ls -r "${___X_CMD_CHAT_SESSION_DIR}/${session}" | ___x_cmd_cmds head  -n "${history_num}"
}

___x_cmd_chat_session_history_mv(){
    :
}

___x_cmd_chat_session_history_cp(){
    :
}

# 1000 => cluster into a xz file
___x_cmd_chat_session_history_pack(){
    local num=1000
    local cur_num; cur_num="$( ___x_cmd_chat_session_history_ls | wc -l )"
    [ "$cur_num" -ge "$num" ] || return 0
    :
}

