factory-ralph-loop
БесплатноБез исполняемых скриптовНе проверенIterative task execution using the Ralph Loop pattern (named after Ralph Wiggum). Use when you need to repeatedly run an agent until a condition is met—fixing…
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
Ralph Loop Pattern
The Ralph Loop (named after Ralph Wiggum) is an agentic pattern where you run an AI agent in a continuous loop until a task is complete. Each iteration starts relatively fresh, with the filesystem serving as persistent memory.
Core Characteristics
- Same systemPrompt repeated — The agent receives consistent instructions each iteration
- Filesystem as memory — Code changes persist on disk between iterations
- Fresh context — Each iteration reduces context pollution vs. single long conversation
- Exit condition — Loop ends when tests pass, lint is clean, or work is exhausted
- Simple orchestrator — Just
while (!done) { run agent }
Basic Structure
const maxIterations = 10;
let iteration = 0;
let done = false;
while (!done && iteration < maxIterations) {
iteration++;
factory.observe.log("info", `Iteration ${iteration}`, { maxIterations });
const result = await factory.spawn({
agent: "worker",
systemPrompt: "You are fixing issues iteratively",
prompt: "Fix the next issue",
model: "anthropic/claude-sonnet-4-6",
step: iteration,
});
// Check exit condition
done = result.exitCode === 0 && result.text.includes("all clean");
if (result.exitCode !== 0) {
factory.observe.log("error", "Agent failed", { iteration, error: result.errorMessage });
break;
}
}
Pattern 1: Fix All Lint Errors
Repeatedly run an agent until lint is clean:
import { spawnSync } from "node:child_process";
const maxIterations = 20;
let iteration = 0;
while (iteration < maxIterations) {
iteration++;
const lintResult = spawnSync("npm", ["run", "lint"], {
cwd: process.cwd(),
encoding: "utf-8",
});
if (lintResult.status === 0) {
factory.observe.log("info", "Lint clean!", { iterations: iteration });
break;
}
factory.observe.log("info", `Iteration ${iteration}`, {
exitCode: lintResult.status,
errorCount: (lintResult.stdout.match(/error/gi) || []).length,
});
const result = await factory.spawn({
agent: "linter",
systemPrompt: `You fix lint errors iteratively.
Run 'npm run lint' to see current errors.
Fix one or more errors, focusing on the most common patterns.
Make minimal, focused changes.`,
prompt: `Fix lint errors. Current output:\n\n${lintResult.stdout}\n${lintResult.stderr}`,
model: "mistral/devstral-2512",
step: iteration,
});
if (result.exitCode !== 0) {
factory.observe.log("error", "Agent failed", { iteration });
break;
}
}
Pattern 2: With Progress Tracking
Accumulate state across iterations to show progress:
import { spawnSync } from "node:child_process";
interface ProgressState {
fixedIssues: string[];
lastErrorCount: number;
stagnantIterations: number;
}
const maxIterations = 20;
let iteration = 0;
const progress: ProgressState = {
fixedIssues: [],
lastErrorCount: Infinity,
stagnantIterations: 0,
};
while (iteration < maxIterations) {
iteration++;
const lintResult = spawnSync("npm", ["run", "lint"], {
cwd: process.cwd(),
encoding: "utf-8",
});
const errorCount = (lintResult.stdout.match(/error/gi) || []).length;
if (lintResult.status === 0) {
factory.observe.log("info", "All issues fixed!", {
iterations: iteration,
fixedIssues: progress.fixedIssues,
});
break;
}
// Track progress
if (errorCount >= progress.lastErrorCount) {
progress.stagnantIterations++;
} else {
progress.stagnantIterations = 0;
}
// Exit if stagnant
if (progress.stagnantIterations >= 3) {
factory.observe.log("warning", "No progress for 3 iterations", { errorCount });
break;
}
factory.observe.log("info", `Iteration ${iteration}`, {
errorCount,
lastErrorCount: progress.lastErrorCount,
fixed: progress.fixedIssues.length,
});
progress.lastErrorCount = errorCount;
const result = await factory.spawn({
agent: "fixer",
systemPrompt: `You fix lint errors iteratively.
Track your progress and avoid repeating unsuccessful approaches.
Previous fixes: ${progress.fixedIssues.join(", ") || "none yet"}
Error count: ${errorCount} (was ${progress.lastErrorCount === Infinity ? "unknown" : progress.lastErrorCount})`,
prompt: `Fix lint errors:\n\n${lintResult.stdout}\n${lintResult.stderr}`,
model: "anthropic/claude-sonnet-4-6",
step: iteration,
});
if (result.exitCode === 0) {
const fixMatch = result.text.match(/fixed?:?\s*(.+)/i);
if (fixMatch) {
progress.fixedIssues.push(fixMatch[1]);
}
}
}
Pattern 3: Loop Until Tests Pass
Run agent repeatedly until test suite passes:
import { spawnSync } from "node:child_process";
const testCommand = "npm test";
const [cmd, ...args] = testCommand.split(" ");
const maxIterations = 10;
let iteration = 0;
while (iteration < maxIterations) {
iteration++;
const testResult = spawnSync(cmd, args, {
cwd: process.cwd(),
encoding
Установить factory-ralph-loop в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл factory-ralph-loop?
Iterative task execution using the Ralph Loop pattern (named after Ralph Wiggum). Use when you need to repeatedly run an agent until a condition is met—fixing all lint errors, passing all tests, or exhausting PRD tasks. The filesystem serves as memory between iterations.
Как установить скилл factory-ralph-loop?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл factory-ralph-loop запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic