Created
August 31, 2025 15:16
-
-
Save stgmt/13b003f50be13e552fbba4ffcd879f09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Новая функция для получения детального ToDo статуса Claude Code | |
| get_todo_status() { | |
| # Извлекаем данные из JSON | |
| local session_id=$(echo "$input" | jq -r '.session_id // ""' 2>/dev/null || echo "") | |
| local transcript=$(echo "$input" | jq -r '.transcript_path // ""' 2>/dev/null || echo "") | |
| local todo_found=0 | |
| local todo_lines=() | |
| # 1. Поиск в ~/.claude/todos/ | |
| if [[ -n "$session_id" && "$todo_found" -eq 0 ]]; then | |
| # Используем find вместо glob для корректной работы | |
| while IFS= read -r -d '' file; do | |
| if [[ -f "$file" ]]; then | |
| # Читаем файл и парсим JSON | |
| if jq -e '. | length > 0' "$file" >/dev/null 2>&1; then | |
| local todos_count=$(jq '. | length' "$file" 2>/dev/null || echo "0") | |
| if [[ "$todos_count" -gt 0 ]]; then | |
| todo_lines+=("📋 ToDo Tasks:") | |
| # Итерируемся по каждой задаче | |
| for ((i=0; i<todos_count; i++)); do | |
| local content=$(jq -r ".[$i].content // \"\"" "$file" 2>/dev/null) | |
| local status=$(jq -r ".[$i].status // \"pending\"" "$file" 2>/dev/null) | |
| # Определяем символ чекбокса | |
| local checkbox="" | |
| case "$status" in | |
| "completed") checkbox="✅" ;; | |
| "in_progress") checkbox="🔄" ;; | |
| *) checkbox="⏳" ;; | |
| esac | |
| # Добавляем строку задачи (обрезаем если слишком длинная) | |
| local task_text="$content" | |
| if [[ ${#task_text} -gt 150 ]]; then | |
| task_text="${task_text:0:147}..." | |
| fi | |
| todo_lines+=(" $((i+1)). $checkbox $task_text") | |
| done | |
| todo_found=1 | |
| break | |
| fi | |
| fi | |
| fi | |
| done < <(find ~/.claude/todos/ -name "${session_id}*" -print0 2>/dev/null) | |
| if [[ "$todo_found" -eq 0 ]]; then | |
| while IFS= read -r -d '' file; do | |
| if [[ -f "$file" ]]; then | |
| if jq -e '. | length > 0' "$file" >/dev/null 2>&1; then | |
| local todos_count=$(jq '. | length' "$file" 2>/dev/null || echo "0") | |
| if [[ "$todos_count" -gt 0 ]]; then | |
| todo_lines+=("📋 ToDo Tasks:") | |
| for ((i=0; i<todos_count; i++)); do | |
| local content=$(jq -r ".[$i].content // \"\"" "$file" 2>/dev/null) | |
| local status=$(jq -r ".[$i].status // \"pending\"" "$file" 2>/dev/null) | |
| local checkbox="" | |
| case "$status" in | |
| "completed") checkbox="✅" ;; | |
| "in_progress") checkbox="🔄" ;; | |
| *) checkbox="⏳" ;; | |
| esac | |
| local task_text="$content" | |
| if [[ ${#task_text} -gt 150 ]]; then | |
| task_text="${task_text:0:147}..." | |
| fi | |
| todo_lines+=(" $((i+1)). $checkbox $task_text") | |
| done | |
| todo_found=1 | |
| break | |
| fi | |
| fi | |
| fi | |
| done < <(find ~/.claude/todos/ -name "*${session_id}*" -print0 2>/dev/null) | |
| fi | |
| fi | |
| # 2. Поиск в transcript файле (упрощенный вид) | |
| if [[ -n "$transcript" && -f "$transcript" && "$todo_found" -eq 0 ]]; then | |
| local todo_count=$(grep -c '"tool_name":"TodoWrite"' "$transcript" 2>/dev/null || echo "0") | |
| if [[ "$todo_count" -gt 0 ]]; then | |
| todo_lines+=("�� ToDo: ${todo_count} задач из transcript") | |
| todo_found=1 | |
| fi | |
| fi | |
| # 3. Поиск в .agents/ (локальные сессии) | |
| if [[ "$todo_found" -eq 0 ]]; then | |
| for agents_dir in .agents/*/; do | |
| if [[ -d "$agents_dir" ]]; then | |
| for todo_file in "$agents_dir"*todo*.json "$agents_dir"*.json; do | |
| if [[ -f "$todo_file" ]]; then | |
| if jq -e '. | length > 0' "$todo_file" >/dev/null 2>&1; then | |
| local todos_count=$(jq '. | length' "$todo_file" 2>/dev/null || echo "0") | |
| if [[ "$todos_count" -gt 0 ]]; then | |
| todo_lines+=("📋 Local ToDo Tasks:") | |
| for ((i=0; i<todos_count; i++)); do | |
| local content=$(jq -r ".[$i].content // \"\"" "$todo_file" 2>/dev/null) | |
| local status=$(jq -r ".[$i].status // \"pending\"" "$todo_file" 2>/dev/null) | |
| local checkbox="" | |
| case "$status" in | |
| "completed") checkbox="✅" ;; | |
| "in_progress") checkbox="🔄" ;; | |
| *) checkbox="⏳" ;; | |
| esac | |
| local task_text="$content" | |
| if [[ ${#task_text} -gt 150 ]]; then | |
| task_text="${task_text:0:147}..." | |
| fi | |
| todo_lines+=(" $((i+1)). $checkbox $task_text") | |
| done | |
| todo_found=1 | |
| break 2 | |
| fi | |
| fi | |
| fi | |
| done | |
| fi | |
| done | |
| fi | |
| # Вывод результатов | |
| if [[ "$todo_found" -eq 0 ]]; then | |
| echo "�� ToDo: нет активных задач" | |
| else | |
| # Выводим каждую строку отдельно | |
| printf "%s\n" "${todo_lines[@]}" | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment