---
name: writer-verifier-loop
description: Orchestrates an implementation loop asking for a spec, planning steps, and repeatedly using writer and verifier subagents (max 10 iterations).
---

# Writer-Verifier Implementation Loop

## Setup

To use this skill, install it by symlinking the skill and the associated subagents into your global pi configuration.

```bash
# Symlink the skill
mkdir -p ~/.pi/agent/skills/writer-verifier
ln -sf "$(pwd)/SKILL.md" ~/.pi/agent/skills/writer-verifier/SKILL.md

# Symlink the agents
mkdir -p ~/.pi/agent/agents
ln -sf "$(pwd)/agents/writer.md" ~/.pi/agent/agents/writer.md
ln -sf "$(pwd)/agents/verifier.md" ~/.pi/agent/agents/verifier.md
```

You are the orchestrator of a strict implementation loop using the `subagent` tool.

## Workflow Instructions

1. **Spec Generation**: Ask the user for the problem details to create a precise specification. Do not proceed until the user approves the spec.
2. **Planning**: Plan the specific steps needed to complete the task based on the spec.
3. **Execution Loop**: For each planned step, run a do-while loop (maximum 10 iterations).
   
   In each iteration, orchestrate the following:
   
   a. **Writer Phase**: Invoke the `subagent` tool with the `writer` agent.
      - **Tool arguments**: `{"agent": "writer", "task": "..."}`
      - Provide ONLY the exact context needed (the specific step, relevant code paths, and the spec). 
      - Inform the writer of any feedback from a previous verifier run if applicable.
      - Ensure the writer is instructed to verify its own code with basic tests.
      
   b. **Verifier Phase**: Invoke the `subagent` tool with the `verifier` agent.
      - **Tool arguments**: `{"agent": "verifier", "task": "..."}`
      - Provide the precise spec and what the writer just produced. 
      - Instruct the verifier to carefully follow the spec, write automated tests, and perform manual testing.
      
   c. **Evaluation**: Check the verifier's feedback.
      - **Success**: If the verifier confirms the task is finished correctly, break the loop and move to the next planned step.
      - **Retry**: If it fails, use the feedback from the verifier as input for the writer in the next iteration.
      - **Limit Hit**: If you hit 10 iterations for a step without success, halt the process and ask the user for help.

## Clean Context Rule
When calling subagents, NEVER pass the entire conversation history. Extract and pass ONLY the precise instructions, the relevant spec portion, and the specific file paths or snippets they need to do their exact job. The power of this loop relies on clean, isolated context windows for both the writer and verifier.
