pua-loop

pua-loop

Popular

PUA Loop — guided iterative development with recurring checks, completion evidence, and pause/abort markers. Use only when the user explicitly asks for loop/自动迭代 mode.

19Kstars
1.2Kforks
Updated 7/16/2026
SKILL.md
read-only
name
pua-loop
description

PUA Loop — guided iterative development with recurring checks, completion evidence, and pause/abort markers. Use only when the user explicitly asks for loop/自动迭代 mode.

PUA Loop — Automated Iteration + Gate Protocol + PUA Quality Engine

autoresearch proved it: 630 lines of Python + Oracle verification ran 100 experiments overnight, producing unforgeable results for every single experiment.
PUA Loop adopts the same gate design: Claude saying "done" doesn't count; only verify_command saying so counts.

Gate Protocol

Adopts 5 design patterns from autoresearch:

Pattern 1: Oracle Isolation

                    Claude outputs <promise>LOOP_DONE</promise>
                                 │
                                 ▼
                    ┌─── Stop Hook (Oracle) ───┐
                    │                          │
                    │  Runs verify_command     │
                    │  (Claude cannot modify   │
                    │   this command)          │
                    │                          │
                    │  exit 0 ──→ ✅ Accept    │
                    │  exit ≠0 ──→ 🚫 Reject   │
                    │    → Feed verify output  │
                    │      back to Claude      │
                    │    → Loop continues      │
                    └──────────────────────────┘

verify_command is set by the user at launch, embedded in the state file frontmatter, and cannot be modified by Claude. This realizes the autoresearch principle that "the agent cannot modify the evaluation function."

Pattern 2: Two-Stage Gate

  • Phase 1 (in-prompt): Claude runs build/test itself to judge whether it is complete.
  • Phase 2 (in-hook): The hook runs verify_command independently to confirm or reject.

Two-stage separation. Even if Claude deceives itself in Phase 1, the Oracle in Phase 2 will block it.

Pattern 3: ASI (Failure Memory)

Results of each iteration are appended to .claude/pua-loop-history.jsonl:

{"iteration":0,"status":"init","verify_command":"npm test","timestamp":"..."}
{"iteration":1,"status":"continue","timestamp":"..."}
{"iteration":2,"status":"promise_rejected","verify_exit":1,"rejections":1,"verify_tail":"3 tests failed","timestamp":"..."}
{"iteration":3,"status":"promise_rejected","verify_exit":1,"rejections":2,"verify_tail":"2 tests failed","timestamp":"..."}
{"iteration":4,"status":"complete","promise_rejections":2,"timestamp":"..."}

git revert rolls back code, but history.jsonl remains unaffected. Claude reads this file every round to avoid repeating failed approaches.

Pattern 4: Stall Detection (Forced Reflection on Consecutive Failures)

promise_rejections Hook Behavior
1-2 Remind: "Last promise was rejected by Oracle"
3-4 REASSESS: "Re-read verification output, list 3 different hypotheses"
5+ Force pivot: "You are solving the wrong problem. Step back to the requirements themselves"

Pattern 5: Infinite Iteration

Default is max_iterations: 0 (unlimited). No artificial cap. The loop never stops simply because it "ran too many rounds" — only the following conditions can terminate it:

  1. <promise> passes Oracle verification
  2. <loop-abort> manual termination signal
  3. max_iterations reached (if set by the user)
  4. User presses Ctrl+C

Core Rules

  1. Load all behavioral protocols from the pua:pua core skill — three red lines, methodology, and pressure escalation apply as usual.
  2. Do not call AskUserQuestion — do not interrupt the user in loop mode; complete all decisions autonomously.
  3. Forbidden to say "I cannot solve this" — there is no right to exit in a loop; exhaust all options before emitting the completion signal.
  4. Every iteration: Read history.jsonl → git log → inspect last changes → execute → verify → repeat.

Launch Method

When the user enters /pua:pua-loop "任务描述", execute the following workflow:

Step 1: Launch PUA Loop

Run the setup script:

bash "${CLAUDE_PLUGIN_ROOT}/scripts/setup-pua-loop.sh" "$ARGUMENTS" --completion-promise "LOOP_DONE"

Important: If the user provides a verifiable command (such as npm test, cargo build, or curl), automatically append --verify '命令'. For example:

  • User says "Fix all tests" → --verify 'npm test'
  • User says "Build a REST API" → --verify 'curl -sf http://localhost:3000/health'
  • User says "Optimize bundle size" → No explicit verify, do not append

If a verification command can be inferred from the task description, proactively append --verify. If uncertain, do not append (fall back to the honor system).

Step 2: Inform the User

Output:

▎ [PUA Loop] Automatic iteration mode started. Unlimited, running until Oracle verification passes.
▎ Completion condition: <promise>LOOP_DONE</promise> (Oracle independent verification)
▎ Cancellation method: Ctrl+C / /cancel-pua-loop
▎ Simple because of trust — but Oracle does not trust you.

Step 3: Start Task Execution

Execute according to the behavioral protocol of the PUA core skill.

Iterative Pressure Escalation

Iteration Round Behavioral Requirement
1-3 Advance steadily, establish a baseline
4-7 Change approaches, do not spin in place
8-15 Review git log + history.jsonl, analyze root causes
16-30 Exhausted all options? Check git diff to ensure you are not repeating
31-50 Stop and re-examine the root cause using a completely different angle
51-100 Step back and question the core requirements themselves
100+ Honest assessment: If truly impossible, emit <loop-abort>

Completion Conditions

Before outputting <promise>LOOP_DONE</promise>, the following must be satisfied:

  1. Core task functionality is implemented
  2. Run the verification command yourself to confirm it passes (Phase 1)
  3. Know that Oracle will run the verification independently again (Phase 2)
  4. Similar issues have been scanned and checked

If Oracle rejects your promise:

  1. Read the verification output returned by the hook
  2. Fix the cause of the verification failure
  3. Run the verification command yourself again to confirm it passes
  4. Output <promise> again

Manual Intervention Signals

<loop-abort> — Terminate

Use when completion is impossible (requires external permissions, fundamental requirement changes). Deletes the state file and terminates the loop.

<loop-pause> — Pause

Use when waiting for user configuration. State is preserved and automatically restored in a new session.
Before outputting, write progress to .claude/pua-loop-context.md.

Prohibited

  • Do not use <loop-abort> to escape difficulties — use only when automation is truly impossible
  • Do not abort just because Oracle rejected the promise — fix the verification issue

Relationship with autoresearch

Dimension karpathy/autoresearch PUA Loop
Oracle evaluate_bpb() physical isolation verify_command in frontmatter, immutable by Claude
Gate Layers 1 layer (metric only) 2 layers (Claude self-verify + hook Oracle)
Failure Memory results.tsv pua-loop-history.jsonl (ASI pattern)
Stall Detection None promise_rejections count + forced REASSESS
Rollback git reset --hard PUA methodology pivot (no rollback, change direction)
Termination NEVER STOP NEVER STOP (except when Oracle verification passes)
Quality Engine None PUA three red lines + pressure escalation