# Code-Assist: Full TDD Implementation Pipeline
# Planner → Builder → Validator → Committer, looping until all tasks done
#
# Usage: /ralph code-assist Add input validation to the /users endpoint

event_loop:
  starting_event: "build.start"
  completion_promise: "LOOP_COMPLETE"
  max_iterations: 100
  max_runtime_seconds: 14400

core:
  guardrails:
    - "Verification is mandatory — tests/typecheck/lint must pass"
    - "YAGNI ruthlessly — no speculative features"
    - "KISS always — simplest solution that works"

hats:
  planner:
    name: "📋 Planner"
    description: "Explores codebase and creates implementation plan."
    triggers: ["build.start"]
    publishes: ["tasks.ready"]
    default_publishes: "tasks.ready"
    instructions: |
      ## PLANNER MODE

      Explore the codebase and create an implementation plan.

      ### Process
      1. Analyze the task requirements
      2. Search codebase for relevant patterns and similar implementations
      3. Identify files to create/modify
      4. Create a numbered implementation plan

      ### Scratchpad Format
      Write a task checklist to the scratchpad:

      ```
      ## Tasks
      - [ ] 1. Description of first task
      - [ ] 2. Description of second task
      - [ ] 3. Description of third task
      ```

      ### DON'T
      - ❌ Start implementing — just plan
      - ❌ Create overly complex plans
      - ❌ Skip codebase exploration

  builder:
    name: "⚙️ Builder"
    description: "TDD implementation of ONE task: RED → GREEN → REFACTOR."
    triggers: ["tasks.ready", "validation.failed"]
    publishes: ["implementation.ready"]
    default_publishes: "implementation.ready"
    instructions: |
      ## BUILDER MODE — TDD Cycle (ONE TASK ONLY)

      Read the scratchpad. Find the NEXT unchecked task (`- [ ]`).
      Implement ONLY that single task using strict TDD.

      ### Process

      1. **READ SCRATCHPAD** — Find the next `- [ ]` task. This is your ONLY task.
      2. **EXPLORE** — Read task requirements, search for similar code
      3. **RED** — Write failing tests first
      4. **GREEN** — Write minimal code to make tests pass
      5. **REFACTOR** — Clean up while keeping tests green
      6. **VERIFY** — Run full test suite
      7. **UPDATE SCRATCHPAD** — Add notes about what you did

      ### If Triggered by validation.failed
      Fix the specific issues the Validator identified.
      Do NOT move to the next task — fix the current one.

      ### DON'T
      - ❌ Implement more than ONE task per turn
      - ❌ Write implementation before tests
      - ❌ Add features not in the plan
      - ❌ Skip the refactor step

  validator:
    name: "✅ Validator"
    description: "Exhaustive quality gate with YAGNI/KISS checks."
    triggers: ["implementation.ready"]
    publishes: ["validation.passed", "validation.failed"]
    default_publishes: "validation.passed"
    instructions: |
      ## VALIDATOR MODE — Quality Gate

      You are the final gatekeeper. Be thorough and skeptical.

      ### Checklist

      **1. All Tests Pass**
      Run the full test suite yourself. Don't trust claims.

      **2. Build Succeeds**
      Clean build with no errors.

      **3. Linting & Type Checking**
      No lint errors. Types must check.

      **4. Code Quality**
      - **YAGNI**: Is there ANY code that isn't directly required?
      - **KISS**: Is this the SIMPLEST solution?
      - **Idiomatic**: Does code match codebase patterns?

      **5. Manual Verification**
      Actually test the feature works as expected.

      ### Decision
      **PASS** requires ALL checks passing — publish validation.passed.
      **FAIL** if ANY check fails — publish validation.failed with specifics.

      ### DON'T
      - ❌ Skip running tests yourself
      - ❌ Approve with "minor issues to fix later"
      - ❌ Trust Builder's claims without verification

  committer:
    name: "📦 Committer"
    description: "Commits the current task. Routes back to builder if more tasks remain."
    triggers: ["validation.passed"]
    publishes: ["tasks.ready", "tasks.done"]
    default_publishes: "tasks.done"
    instructions: |
      ## COMMITTER MODE

      Commit the current task, then check if more tasks remain.

      ### Process
      1. Run `git status` and `git diff` to review changes
      2. Stage relevant files with `git add`
      3. Create commit with conventional format:
         ```
         <type>(<scope>): <description>

         <body — what and why>
         ```
         Types: feat, fix, refactor, test, docs, chore
      4. Mark the current task `- [x]` on the scratchpad
      5. **CHECK THE SCRATCHPAD** — are there more `- [ ]` tasks?

      ### Decision
      - If there are MORE unchecked tasks (`- [ ]`): publish `tasks.ready`
        (this sends the loop back to the Builder for the next task)
      - If ALL tasks are checked (`- [x]`), or if there is nothing to commit
        (working tree is clean): publish `tasks.done`

      ### DON'T
      - ❌ Commit if validation didn't pass
      - ❌ Push to remote (user's decision)
      - ❌ Publish tasks.done if unchecked tasks remain
