#!/usr/bin/env bash
set -euo pipefail
source /root/.local/share/admin-menu/common.sh
helper="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/codex-kiln-sessions.py"
rows=$(python3 "$helper" list) || exit $?
if [[ -z "$rows" ]]; then
    printf 'В рабочих каталогах сайта, бота и совместного KILN нет сохранённых активных сессий.\n' >&2
    exit 0
fi
mapfile -t options <<< "$rows"
selected=$(run_gum choose --header 'Вернуться в сессию KILN · время по Москве' \
    --label-delimiter '|' --cursor '> ' --cursor-prefix '' \
    --unselected-prefix '  ' --no-show-help --height 20 "${options[@]}") || exit 0
[[ -n "$selected" ]] || exit 0
python3 "$helper" resume "$selected"
