name: issue-refinement
description: |
  Progressively refine all active issues through format → score → refine pipeline.
  Delegates refinement to the refine-to-ready-issue sub-loop for each issue.
  Commits every 5 actions and continues until all issues meet quality thresholds.
initial: init
states:
  init:
    action: mkdir -p .loops/tmp && rm -f .loops/tmp/issue-refinement-commit-count
    action_type: shell
    next: evaluate
  evaluate:
    action: ll-issues next-action
    action_type: shell
    capture: "classify"
    evaluate:
      type: exit_code
    on_yes: done
    on_no: parse_id
    on_error: done
  parse_id:
    action: echo "${captured.classify.output}" | awk 'NR==1{printf $2}'
    action_type: shell
    capture: "input"
    evaluate:
      type: exit_code
    on_yes: run_refine_to_ready
    on_error: evaluate
  run_refine_to_ready:
    loop: refine-to-ready-issue
    context_passthrough: true
    on_yes: check_commit
    on_no: check_commit
  check_commit:
    action: |
      mkdir -p .loops/tmp
      FILE=".loops/tmp/issue-refinement-commit-count"
      N=$(cat "$FILE" 2>/dev/null || echo 0)
      N=$((N + 1))
      printf '%s' "$N" > "$FILE"
      if [ $((N % 5)) -eq 0 ]; then echo "COMMIT"; else echo "SKIP"; fi
    action_type: shell
    evaluate:
      type: output_contains
      pattern: "COMMIT"
    on_yes: commit
    on_no: evaluate
    on_error: evaluate
  commit:
    action_type: prompt
    action: /ll:commit
    next: evaluate
  done:
    terminal: true
max_iterations: 200
timeout: 86400
on_handoff: spawn
