Autonomous keep-or-revert experiment loop. Iteratively optimizes any metric through single atomic changes, committing before verification and discarding failures. Two execution modes: ralph (same-session, quick iterations) and scheduled (cron trigger, fresh session per iteration — for multi-hour iterations). Triggers: "autoresearch", "/autoresearch", "auto research", "optimize metric", "автоисследование", "оптимизируй метрику"
Autonomous keep-or-revert experiment loop. One atomic change per iteration — commit, verify, keep or discard.
/autoresearch <goal in natural language>
/autoresearch --continue # used by scheduled trigger, skips setup
$ARGUMENTS
Arguments: <goal> — what you want to optimize, in natural language.
If autoresearch-scratchpad.md already exists in the project root OR $ARGUMENTS contains --continue — skip to Phase 1.
Extract the optimization goal from $ARGUMENTS. If empty — ask what to optimize (AskUserQuestion).
Ask all questions in ONE AskUserQuestion call:
src/api/, train.py, tests/)pytest -q 2>&1 | tail -1, wc -l src/*.py, ab -n 100 http://localhost:8080/ 2>&1 | grep 'Time per request')pytest, npm test, cargo check). Leave empty to skipralph (default) — same session, ralph-loop re-injects after each iteration. Best for quick iterations (<30 min each). Fails if session context fills before max_iterations.scheduled — cron-triggered, fresh session per iteration. Best for long iterations (>1h each — ML training, long benchmarks, integration suites). Each iteration gets a full context window.mode = scheduled) — how long does ONE iteration typically take? Used to compute cron schedule (trigger fires every estimate + 30min buffer).Use session-specific temp files to avoid collisions with concurrent sessions:
AUTORESEARCH_TMP="/tmp/autoresearch-$(git rev-parse --short HEAD)-$$"
Run the metric command once. Verify a number can be extracted from output:
<metric_cmd> > ${AUTORESEARCH_TMP}-run.log 2>&1
grep -oE '[0-9]+\.?[0-9]*' ${AUTORESEARCH_TMP}-run.log | tail -1
If no number found — report error, ask user to fix the metric command. Do NOT proceed until a number is extractable.
git checkout -b autoresearch/<goal-slug>
Where <goal-slug> is the goal slugified (lowercase, spaces to dashes, special chars removed, max 40 chars).
Run metric command, record the extracted number as baseline (iteration 0).
autoresearch-scratchpad.md (config in frontmatter + empty working memory):
---