lee-to/ai-factory/aif-loop
- community
Checking that the SKILL.md file is still in the repository.
Run a strict multi-iteration Reflex Loop with phases (PLAN, PRODUCE||PREPARE, EVALUATE, CRITIQUE, REFINE) to improve an artifact until quality gates pass or iteration limits are reached. Use when user asks for iterative refinement, quality-gated generation, or "generate -> critique -> refine" loops.
Install
npx vskill@latest install lee-to/ai-factory/aif-loopSKILL.md
Loop - Reflex Iteration Workflow
Run a result-focused iterative loop with strict phase contracts, evaluation rules, and persistent state between sessions.
Step 0: Load Config
FIRST: Read .ai-factory/config.yaml if it exists to resolve:
- Paths:
paths.description,paths.architecture,paths.rules_file,paths.roadmap,paths.plan,paths.plans, andpaths.evolution - Language:
language.uifor prompts,language.artifactsfor generated content
If config.yaml doesn't exist, use defaults:
- Paths:
.ai-factory/for all artifacts - Language:
en(English)
Terminology:
- loop = one full execution for a task alias (stored in
run.json, identified byrun_id) - iteration = one cycle inside that loop
Core Idea
Each iteration executes 6 phases with parallel execution where possible:
PLAN- short plan for current iterationPRODUCE- produce oneartifact.md← runs in parallel with PREPAREPREPARE- generate check scripts and test definitions from rules ← runs in parallel with PRODUCEEVALUATE- run prepared checks + content rules against artifact, score result. Uses parallelTaskagents for independent check groupsCRITIQUE- precise issues + fixes (only if fail)REFINE- rewrite artifact using critique (only if fail)
Stop when quality is good enough, no major issues remain, the user stops the run, progress stagnates, or a resource guard trips (optional time budget, iteration limit). The full precedence order is in Step 5.
Persistence Contract
Use exactly 3+1 files for state inside the resolved evolution directory (where current.json exists only while a loop is active):
Do not create extra index files or per-iteration folder trees unless user explicitly asks.
File Roles
current.json: pointer to active loop only; delete it when loop becomescompleted/stopped/failedrun.json: single source of truth for current loop statehistory.jsonl: append-only event log (one JSON object per line)artifact.md: single source of truth for artifact content (written after PRODUCE and REFINE phases, never duplicated inrun.json)
Command Modes
Parse $ARGUMENTS:
status- show active loop status fromcurrent.jsonand stopresume [alias]- continue active loop or loop by aliasstop [reason]- stop active loop with reason (user_stopif omitted)new <task>or no mode + task text - start new looplist- list all task aliases with status (running/stopped/completed/failed)history [alias]- show event history for a loop (default: active loop)clean [alias|--all]- remove loop files for a stopped/completed/failed loop (requires user confirmation, always confirm before deleting)
If no task and no active loop exists, ask user for task prompt.
Step 0: Load Context
Read these files if present:
- the resolved description path
- the resolved architecture path
- the resolved RULES.md path
Use them to keep outputs aligned with project conventions.
Read `.ai-factory/skill-context/aif-loop/SKILL.md` — MANDATORY if the file exists.
This file contains project-specific rules accumulated by /aif-evolve from patches, codebase conventions, and tech-stack analysis. These rules are tailored to the current project.
How to apply skill-context rules:
- Treat them as project-level overrides for this skill's general instructions
- When a skill-context rule conflicts with a general rule written in this SKILL.md,
the skill-context rule wins (more specific context takes priority — same principle as nested CLAUDE.md files)
- When there is no conflict, apply both: general rules from SKILL.md + project rules from skill-context
- Do NOT ignore skill-context rules even if they seem to contradict this skill's defaults —
they exist because the project's experience proved the default insufficient
- CRITICAL: skill-context rules apply to ALL outputs of this skill — including the generated
artifact, run state, and evaluation criteria. If a skill-context rule says "artifact MUST include X" or "evaluation MUST check Y" — you MUST comply. Producing loop outputs that violate skill-context rules is a bug.
Enforcement: After generating any output artifact, verify it against all skill-context rules. If any rule is violated — fix the output before presenting it to the user.
Step 0.1: Handle Non-Iteration Commands
If command is status, stop, list, history, or clean, execute and stop:
- `status`: read
current.json; if file exists, read pointedrun.jsonand displayalias | status | iteration | phase | current_step | last_score | updated_at, pluscompleted_phase_seconds / max_completed_phase_secondswhen a budget is set; if file is missing, report that no loop is active - `stop [reason]`: stop active running loop only; set
run.json.status = "stopped"andrun.json.stop.reason = <reason or "user_stop">, appendstoppedevent tohistory.jsonl, then deletecurrent.json(active pointer cleared) and exit - `list`: scan the resolved evolution directory, read each
run.json, display table ofalias | status | iteration | last_score | updated_at - `history [alias]`: read
history.jsonlfor the alias (or active loop), display formatted event timeline - `clean [alias|--all]`: show what will be deleted, ask for explicit user confirmation via
AskUserQuestion, then delete loop directory. Only clean stopped/completed/failed loops — refuse to clean running loops. Updatecurrent.jsonif needed.
Step 1: Initialize or Resume Loop
1.1 Ensure directories
1.2 Alias and IDs (new loop)
Generate:
task_alias: lowercase hyphen slug (3-64 chars)run_id:<task_alias>-<yyyyMMdd-HHmmss>
1.3 Write current.json
1.4 Write initial run.json
1.5 Resume Logic
When resuming a loop:
- Read
run.jsonto getcurrent_stepanditeration - Read last event from
history.jsonlto confirm consistency - If
run.json.current_stepindicates a phase was interrupted:
- Re-execute from that phase (do not skip)
PRODUCE_PREPARE: always re-run both PRODUCE and PREPARE (idempotent — artifact overwrites, checks regenerate)
- If
run.json.statusisstopped,completed, orfailed, inform user and suggestnew(forfailedruns, also show the lastphase_errorevent fromhistory.jsonlso user understands what went wrong) - Discard a stale
phase_started_epoch_seconds: set it to the currentdate +%swhen the interrupted phase actually re-starts. The interrupted attempt contributes nothing to the budget — onlycompleted_phase_secondsalready accumulated from finished segments carries over (seereferences/ACTIVE-TIME-BUDGET.md).
Step 2: Interactive Setup (new loop)
Quick mode (default, confirmation-first)
If the task prompt contains enough context to infer task type and ideal result:
- Auto-detect task type from prompt (API spec, code, docs, config)
- Load matching template from
references/CRITERIA-TEMPLATES.md - Draft inferred rules, phase thresholds (fallback: A=0.8, B=0.9), max iterations (default:
4), and a completed-phase time budget (default:none; infer one only per the setup rules inreferences/ACTIVE-TIME-BUDGET.md) - Show inferred settings as a draft summary, with the normalized budget next to max iterations
- Always ask explicit confirmation of success criteria (rules/thresholds) via
AskUserQuestion, even if criteria were already present in the task text - Always ask explicit confirmation of max iterations via
AskUserQuestion, even if iteration count was already present in the task text - Ask explicit confirmation of the time budget via
AskUserQuestionwhenever the drafted value is notnull, always offeringnoneas an option - If user changes criteria, max iterations, or the budget, update the draft and re-confirm all three fields
- Start iteration 1 only after the confirmations are explicit
- If task type cannot be auto-detected (ambiguous or mixed prompt), fall through to full setup immediately
Full setup
Critical guardrail:
- Always re-ask and explicitly confirm success criteria and max iterations, even if both are already written in the task prompt.
Ask concise setup questions before first iteration:
- Task type - what kind of artifact? (API spec, code, docs, config, other) - used to load template from
references/CRITERIA-TEMPLATES.md - Ideal result definition
- Mandatory checks (tests, schema/contract, specific requirements)
- Quality threshold (A/B phases)
- Max iterations (default:
4) - Completed-phase time budget in seconds (default:
none) — offernoneexplicitly; a domain-level timeout is not a loop budget - What counts as a major issue
- Explicit confirmation: "Confirm these success criteria?"
- Explicit confirmation: "Confirm max iterations = N?"
- Explicit confirmation of the budget when it is not
none: "Confirm time budget = N seconds?"
Generate evaluation rules from answers:
- Load matching template from
references/CRITERIA-TEMPLATES.mdas starting point - Add task-specific rules based on ideal result and mandatory checks
- Let user review and adjust rules before starting
Persist answers and generated rules inside run.json.criteria (snapshot for reproducibility).
Never treat criteria, iteration limits, or a time budget parsed from task text as final until the user explicitly confirms them.
Normalization rules before persisting:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationWarning, 62 of 100Marginal. 1 run. Evaluated 7 months ago.
Source
- SKILL.md in the repositoryCheckingskills/aif-loop/SKILL.md
Popularity
- Repository stars
- 425
- Repository forks
- 48
- Repository npm downloads, 7 days
- 479
- 7-day trend score
- 47
Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 29 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/lee-to/ai-factory/aif-loop)