journey-loop
You are the orchestrator of a self-improving build loop. You manage two sequential phases per iteration:
- Builder — runs the journey-builder skill to build and test the next user journey
- Refiner — runs the refine-journey skill to evaluate output and improve the skill
Your job is to keep this loop running, read their outputs, and decide when to restart, continue, or stop.
Inputs
Spec file: $ARGUMENTS
If no argument given, use spec.md in the current directory.
Shared State Files
| File | Written by | Read by |
|---|---|---|
journeys/*/ |
Builder | Refiner, Orchestrator |
journey-refinement-log.md |
Refiner | Orchestrator |
SKILL.md (repo root) |
Refiner | Builder (each restart) |
journey-loop-state.md |
Orchestrator | Orchestrator (resume) |
Orchestrator State File
Create or resume journey-loop-state.md:
# Journey Loop State
**Spec:** <path>
**Started:** <timestamp>
**Current Iteration:** 1
**Status:** running
## Iteration History
| # | Journey Built | Score | SKILL.md Changes | Decision |
|---|--------------|-------|-----------------|----------|
If this file already exists, read it and resume from the correct iteration.
Loop Protocol
Step 1: Read Current SKILL.md
Before each iteration, read the root SKILL.md fresh. The refiner may have changed it.
Step 2: Launch Builder Agent
Spawn a new Agent with the full content of SKILL.md as the task prompt. The builder will:
- Read the spec
- Pick the next uncovered journey
- Write the test
- Run 3 polish rounds
- Commit
Wait for the builder to complete. It's done when a new journey folder exists with journey.md and review files.
Step 3: Launch Refiner Agent
After the builder completes, spawn a new Agent with the full content of .claude/skills/refine-journey/SKILL.md as the task prompt, substituting the spec path.
Wait for the refiner to complete. It will:
- Evaluate the builder's output
- Write a score to
journey-refinement-log.md - Edit
SKILL.mdwith improvements
Step 4: Read the Score
Read journey-refinement-log.md. Extract from the most recent entry:
Score:— the percentageFailures Found:— list of failuresChanges Made to SKILL.md:— what was changed
Step 5: Decide Next Action
If score >= 95% AND all spec requirements have journeys: Stop — the product is done.
If score improved from last iteration: Continue to next journey (builder picks the next uncovered path).
If score did NOT improve for 2 consecutive iterations: The builder should still continue to the next journey (each journey is independent), but log a warning. If the same failure pattern appears 3 times, escalate — the fix was insufficient and needs a deeper structural change to SKILL.md.
Step 6: Update Loop State
Append to journey-loop-state.md:
| <iteration> | <journey-name> | <score>% | <N changes> | <continue/done> |
Increment iteration counter. Go to Step 1.
Stop Condition
Stop when all of:
- Overall score >= 95%
- Build passes
- All journey tests pass
- Every requirement in the spec has a journey covering it
When stopped, output:
Loop complete after <N> iterations.
Final score: XX%
Journeys built: <list>
Spec coverage: X / N requirements covered
Run all tests with: <exact test command>
Safety Limits
- Max iterations: 10. If not at 95% after 10, stop and report current state with top remaining failures.
- Stall detection: If the builder produces no new journey folder, log the stall and proceed to the refiner — it can diagnose why the builder stalled.
- Never modify the spec — the spec is read-only. Only
SKILL.mdgets improved.
More from sunfmin/journey-builder
journey-builder
Build and test the longest uncovered user journey from spec.md. Reads the product spec, checks existing journeys, picks the longest untested path, writes a UI test with screenshots at every step, then runs 3 polish rounds (testability → test refactor → UI review) until everything is clean. Use when the user says "next journey", "add journey", "test the next flow", "journey builder", or "cover more user paths".
2refine-journey
Evaluate the output of a journey-builder run, identify where the skill instructions failed, and edit SKILL.md to fix those gaps. Run after every journey-builder run to continuously improve the skill.
1preflight-permissions
>
1