name: "general-task"
initial: define_done
max_iterations: 100
on_handoff: spawn

states:
  define_done:
    action: >
      Your task is: ${context.input}

      Before planning or executing anything, write a concrete Definition of Done
      to ${env.PWD}/.loops/tmp/general-task-dod.md in this format:
      ```
      # Definition of Done
      ## Verification Criteria
      - [ ] <Specific, verifiable criterion>
      - [ ] <Another criterion — e.g., "File X exists", "Tests pass", "Output contains Y">
      ```

      Each criterion must be independently verifiable by checking files, running commands,
      or reading outputs. Do NOT start any work. Only write the DoD file.
    action_type: prompt
    next: plan
    on_error: failed

  plan:
    action: >
      Your task is: ${context.input}

      Before starting, decompose this task into a numbered list of discrete,
      independently completable steps. Each step should be small enough to
      complete in a single focused session.

      Write the step list to ${env.PWD}/.loops/tmp/general-task-plan.md in this format:
      ```
      # Task Plan
      - [ ] Step 1: ...
      - [ ] Step 2: ...
      ```

      Do NOT start executing any steps yet. Only write the plan file.
    action_type: prompt
    next: execute
    on_error: failed

  execute:
    action: >
      Your task is: ${context.input}

      A step-by-step plan exists at ${env.PWD}/.loops/tmp/general-task-plan.md.
      Read it, find the FIRST unchecked step (- [ ]), complete ONLY that step,
      then mark it done (- [x]) in the file.

      Do not work on multiple steps. Complete one step, update the plan file, stop.
    action_type: prompt
    next: check_done
    on_error: failed

  check_done:
    action: >
      Read the Definition of Done at ${env.PWD}/.loops/tmp/general-task-dod.md.
      For EACH criterion, actively verify it is met by checking the actual state of
      the filesystem, running relevant commands, or reading relevant files.
      Do NOT assume — verify by evidence.

      Update the DoD file, marking each criterion [x] if verified or leaving [ ]
      with a one-line note explaining what is missing.
    action_type: prompt
    evaluate:
      type: llm_structured
      prompt: >
        Read ${env.PWD}/.loops/tmp/general-task-dod.md.
        Are ALL criteria marked [x]?
        Answer YES only if every criterion is checked off. Answer NO if any remain unchecked.
    on_yes: done
    on_no: continue_work
    on_error: failed

  continue_work:
    action: >
      Your task is: ${context.input}

      A step-by-step plan exists at ${env.PWD}/.loops/tmp/general-task-plan.md.
      Read it, find the FIRST unchecked step (- [ ]), complete ONLY that step,
      then mark it done (- [x]) in the file.

      Do not work on multiple steps. Complete one step, update the plan file, stop.
    action_type: prompt
    next: check_done
    on_error: failed

  done:
    terminal: true

  failed:
    terminal: true
