operations-autoresearch
Autonomous goal-directed iteration loop that improves any OS file — skills, CLAUDE.md, brain notes, context files, or routine commands — against criteria you define. Inspired by Karpathy's autoresearch pattern.
Automation Level
CHECKPOINT — always shows improved file to user before writing. Never overwrites without confirmation. Loop itself runs autonomously once started.
Architecture: Four-Way Separation
Both eval modes maintain strict separation so no role can game the evaluation.
| Role |
Who |
Knows eval details? |
Knows history? |
| Optimizer (you, main agent) |
Makes changes, reads metric numbers, decides keep/discard |
NO — never reads eval.py source or rubric scoring examples |
YES — reads logs, plans changes |
| Eval Agent |
autoresearch-eval-agent |
YES — writes eval.py OR rubric.md |
NO |
| Test Runner |
autoresearch-test-runner |
NO — fresh context every time |
NO |
| Judge |
eval.py (deterministic) OR autoresearch-judge agent (AI judge) |
IS the eval / follows rubric |
NO |
Inputs
- The target file path (skill, CLAUDE.md, brain note, context file, command)
- User-confirmed quality criteria
- All reference files the target depends on
Outputs
inbox/outputs/html/YYYY-MM-DD-operations-autoresearch-[target-name].html — live dashboard
inbox/outputs/json/YYYY-MM-DD-operations-autoresearch-[target-name].jsonl — iteration log
- The improved target file (shown to user before writing — CHECKPOINT)
The Three Rules (Criteria Validation)
Every criterion MUST pass these before entering the loop. Bad criteria produce bad evals.
Rule 1: State the exact condition, not the goal.
| Bad |
Good |
| "Make the hook short" |
"First line must be under 136 characters" |
| "Should be professional" |
"Contains no exclamation marks and no ALL CAPS words (3+ letters)" |
| "Include relevant data" |
"Contains at least one specific number or statistic" |
Rule 2: One criterion, one variable. If you'd use "and" to combine two checks, split them.
Rule 3: Define the test (optional). Describe what to count, what regex to match, or what structure to look for. Helps the eval agent write better checks.
If the user provides criteria that violate The Three Rules, rewrite them — show the before/after.
Phase 0: Session Setup
When the user names a target file or says "autoresearch [something]":
Resolve the target file path:
- Skill name →
.claude/skills/[skill-name]/SKILL.md
- "CLAUDE.md" →
CLAUDE.md
- "brain/acquisition" or "acquisition-moc" →
brain/acquisition-moc.md
- "context/my-voice-dna" →
context/my-voice-dna.md
- "[command name]" or "/content" →
.claude/commands/[command-name].md
Read the target file.
Determine the output file type the target produces (for skills and commands — check the output section of the file):
- Skills that produce markdown →
.md
- Skills that produce HTML →
.html
- Skills that produce JSON →
.json
- Skills that produce PDFs →
.pdf
- Skills that produce images →
.png
- Config/context/brain files →
.md (the file itself is the output)
Create the session directory: inbox/outputs/autoresearch-sessions/YYYY-MM-DD-[target-name]/
Create subdirectory: inbox/outputs/autoresearch-sessions/YYYY-MM-DD-[target-name]/outputs/
Write session config to autoresearch-session.md in the session directory.
Explain The Three Rules in chat. Then propose 5-7 quality criteria specific to this file type.
Examples by target type:
- Skill: trigger phrases exist, numbered steps, correct output routing, edge cases section, context reads appropriate files
- CLAUDE.md: every rule has a concrete example, no vague instructions, cross-references are accurate, all referenced paths exist
- Brain MOC: covers key patterns from real outputs, links to sources, no stale references
- Context file: every section under 200 words, no outdated info, actionable summary present
- Routine command: every skill in the workflow table exists at the named path, all steps are numbered, output destination named
Use AskUserQuestion:
- Question: "Do these quality criteria look right?"
- Options: "These look good" / "Adjust some"
Use AskUserQuestion (separate step):
- Question: "Which evaluation mode?"
- Options: "Deterministic (checks things mechanically — structure, format, keywords)" / "AI Judge (LLM scores subjective quality — tone, authenticity, completeness)"
Use AskUserQuestion (separate step):
- Question: "How many iterations? (5 recommended)"
- Options: "5 (recommended)" / "10" / "20"
Phase 1: Build the Eval System
Spawn autoresearch-eval-agent with:
- Target file path + contents
- Confirmed criteria list
- Session directory path
- Eval mode (deterministic or ai_judge)
- Output file extension
Deterministic: agent generates eval.py + test_cases.json
AI Judge: agent generates rubric.md + test_cases.json
Read the generated file (eval.py or rubric.md) and show it to the user. Use AskUserQuestion:
- Question: "Does this eval capture what you mean?"
- Options: "Looks good" / "Adjust it"
If adjust: spawn eval agent again with specific feedback.
Once confirmed — eval artifacts are READ-ONLY for the rest of the session. Never modify eval.py, rubric.md, or test_cases.json during the loop.
Phase 2: Baseline (Iteration 0)
Spawn autoresearch-test-runner with:
Execute the target file at [full path to target].
Test cases are at [session directory]/test_cases.json.
The working project is at [YOUR_PROJECT_PATH]. Replace with your actual absolute path before running.
Reference files the target depends on (read these first):
- [list ALL files the target references: context/, brain/, design-kit/, etc.]
Use all available tools to produce real outputs.
Save each output to [session directory]/outputs/output_00.[ext] through output_09.[ext].
Follow the target exactly. One output per test case. No commentary.
IMPORTANT: Scan the target file for any file paths, references/ mentions, context/ reads, or [[wikilinks]] — list all of them explicitly in the prompt.
Evaluate the baseline:
- Deterministic:
python [session directory]/eval.py [session directory]/outputs/ — parse METRIC pass_rate=X.XXXX
- AI Judge: Spawn
autoresearch-judge with outputs/ + rubric.md — parse quality_score from judge-scores.json
Record baseline in autoresearch-log.jsonl. Create initial dashboard from references/dashboard-template.html.
Phase 3: The Loop
Repeat for the chosen iteration count (stop early if metric plateaus for 10+ consecutive iterations or user says "stop"):
Step 1 — Review
- Read current target file
- Read last 5 entries from
autoresearch-log.jsonl
- Read failure details from last eval (which assertions fail most? which test cases are hardest?)
- Read
autoresearch-ideas.md if it exists
Step 2 — Ideate
- Pick ONE change to try. One hypothesis, one variable.
- Reason: target the weakest area from the last eval's assertion breakdown or rubric breakdown.
- Write the hypothesis in plain English before making the change.
Step 3 — Modify
- Copy target file to
[target-filename].backup in the session directory
- Make EXACTLY ONE change to the target file
Step 4 — Execute (via Test Runner)
- Scan the updated target file for reference files again (they may have changed)
- Spawn
autoresearch-test-runner with the same prompt as Phase 2, updated with any new reference file paths
Step 5 — Evaluate
- Deterministic: Run
python eval.py outputs/ — parse METRIC pass_rate=X.XXXX
- AI Judge: Spawn
autoresearch-judge — parse quality_score from judge-scores.json
Step 6 — Decide
| Condition |
Action |
| Metric improved |
KEEP — change stays, update .backup to new version |
| Metric same or worse |
DISCARD — restore from .backup |
| Eval crashed |
CRASH — restore from .backup, note the error |
Step 7 — Log + Dashboard
Append to autoresearch-log.jsonl:
{"iteration": 1, "timestamp": "ISO", "hypothesis": "...", "metric_name": "pass_rate", "metric_value": 0.70, "baseline": 0.50, "best_so_far": 0.70, "delta": "+0.20", "eval_mode": "deterministic", "assertion_breakdown": {"assertion_1": 9, "assertion_2": 7}, "status": "keep"}
AI Judge format uses "rubric_breakdown": {"criterion_1": 3.8, "criterion_2": 3.2} instead.
Update dashboard HTML with current stats.
Step 8 — Stuck Check
If 3+ consecutive discards on similar ideas → pivot radically. Try a completely different approach.
Stopping
When the loop finishes (iteration count reached, plateau, or user says "stop"):
Write final summary to autoresearch-worklog.md:
- Total iterations run
- Best metric achieved vs baseline
- Top 3 most impactful changes
- Which criteria improved most
- Untried ideas (from
autoresearch-ideas.md)
Show the user the improved target file. Use AskUserQuestion:
- Question: "Write the improved version to [target path]?"
- Options: "Yes, write it" / "Skip" / "Edit first"
On confirmation: write the improved file to the original target path.
Save dashboard to inbox/outputs/html/YYYY-MM-DD-operations-autoresearch-[target-name].html
Save log to inbox/outputs/json/YYYY-MM-DD-operations-autoresearch-[target-name].jsonl
Separation Rules
- You are the optimizer. NEVER generate outputs, write eval code, or score quality yourself.
- Eval artifacts (eval.py, rubric.md, test_cases.json) are READ-ONLY once confirmed.
- Test runner NEVER sees the eval or rubric. Fresh context every time.
- Judge NEVER sees iteration history. Fresh context every time. (AI judge mode)
- You NEVER read eval.py source code or rubric scoring examples. Only read the metric number.
Edge Cases
| Situation |
What to do |
| User says "autoresearch" without a target |
Ask: "Which file do you want to optimize? (skill name, CLAUDE.md, context/[file], brain/[moc], or /command name)" |
| Target file doesn't exist |
Stop and flag: "I can't find [path]. Check the name and try again." |
| Eval.py crashes with syntax error |
Spawn eval agent again with the error message. Fix before starting the loop. |
| Skill produces binary output (PDF, image) |
Deterministic eval checks file exists + non-empty only. Flag to user that content-level scoring isn't available. |
| All 20 iterations discard |
Show user the final summary with a note: "The criteria may be too strict or the target may need manual redesign first." |
| User messages during loop |
Pause, respond, then offer to resume: "Want me to continue from iteration X?" |
| Target is operations-autoresearch itself |
Skip gracefully — don't recurse. |
What Good Looks Like
The target file improves measurably across the iteration log. The dashboard shows a clear upward trend in the metric with the specific changes that drove each keep. The user sees a before/after and confirms. The session leaves a JSONL audit trail and dashboard in inbox/outputs/ for reference.
1---2name: operations-autoresearch3description: Autonomous optimization loop that continuously improves any file in the OS against measurable quality criteria. Two evaluation modes — deterministic (eval.py with proxy heuristics) or AI judge (LLM rubric scoring). Full four-way role separation. Use this skill when the user says "autoresearch [file or skill name]", "optimize this skill", "improve my voice DNA", "sharpen this command", "autoresearch CLAUDE.md", "make this better automatically", "run the optimization loop on", or "iterate on this until it's better". Works on: skills, CLAUDE.md, brain MOCs, context files, routine commands.4---56# operations-autoresearch78Autonomous goal-directed iteration loop that improves any OS file — skills, CLAUDE.md, brain notes, context files, or routine commands — against criteria you define. Inspired by Karpathy's autoresearch pattern.910## Automation Level11CHECKPOINT — always shows improved file to user before writing. Never overwrites without confirmation. Loop itself runs autonomously once started.1213## Architecture: Four-Way Separation1415Both eval modes maintain strict separation so no role can game the evaluation.1617| Role | Who | Knows eval details? | Knows history? |18|------|-----|---------------------|---------------|19| **Optimizer** (you, main agent) | Makes changes, reads metric numbers, decides keep/discard | NO — never reads eval.py source or rubric scoring examples | YES — reads logs, plans changes |20| **Eval Agent** | `autoresearch-eval-agent` | YES — writes eval.py OR rubric.md | NO |21| **Test Runner** | `autoresearch-test-runner` | NO — fresh context every time | NO |22| **Judge** | `eval.py` (deterministic) OR `autoresearch-judge` agent (AI judge) | IS the eval / follows rubric | NO |2324---2526## Inputs27- The target file path (skill, CLAUDE.md, brain note, context file, command)28- User-confirmed quality criteria29- All reference files the target depends on3031## Outputs32- `inbox/outputs/html/YYYY-MM-DD-operations-autoresearch-[target-name].html` — live dashboard33- `inbox/outputs/json/YYYY-MM-DD-operations-autoresearch-[target-name].jsonl` — iteration log34- The improved target file (shown to user before writing — CHECKPOINT)3536---3738## The Three Rules (Criteria Validation)3940Every criterion MUST pass these before entering the loop. Bad criteria produce bad evals.4142**Rule 1: State the exact condition, not the goal.**4344| Bad | Good |45|-----|------|46| "Make the hook short" | "First line must be under 136 characters" |47| "Should be professional" | "Contains no exclamation marks and no ALL CAPS words (3+ letters)" |48| "Include relevant data" | "Contains at least one specific number or statistic" |4950**Rule 2: One criterion, one variable.** If you'd use "and" to combine two checks, split them.5152**Rule 3: Define the test (optional).** Describe what to count, what regex to match, or what structure to look for. Helps the eval agent write better checks.5354If the user provides criteria that violate The Three Rules, rewrite them — show the before/after.5556---5758## Phase 0: Session Setup5960When the user names a target file or says "autoresearch [something]":61621. Resolve the target file path:63 - Skill name → `.claude/skills/[skill-name]/SKILL.md`64 - "CLAUDE.md" → `CLAUDE.md`65 - "brain/acquisition" or "acquisition-moc" → `brain/acquisition-moc.md`66 - "context/my-voice-dna" → `context/my-voice-dna.md`67 - "[command name]" or "/content" → `.claude/commands/[command-name].md`68692. Read the target file.70713. Determine the output file type the target produces (for skills and commands — check the output section of the file):72 - Skills that produce markdown → `.md`73 - Skills that produce HTML → `.html`74 - Skills that produce JSON → `.json`75 - Skills that produce PDFs → `.pdf`76 - Skills that produce images → `.png`77 - Config/context/brain files → `.md` (the file itself is the output)78794. Create the session directory: `inbox/outputs/autoresearch-sessions/YYYY-MM-DD-[target-name]/`80 Create subdirectory: `inbox/outputs/autoresearch-sessions/YYYY-MM-DD-[target-name]/outputs/`81825. Write session config to `autoresearch-session.md` in the session directory.83846. **Explain The Three Rules in chat.** Then propose 5-7 quality criteria specific to this file type.85 Examples by target type:86 - **Skill:** trigger phrases exist, numbered steps, correct output routing, edge cases section, context reads appropriate files87 - **CLAUDE.md:** every rule has a concrete example, no vague instructions, cross-references are accurate, all referenced paths exist88 - **Brain MOC:** covers key patterns from real outputs, links to sources, no stale references89 - **Context file:** every section under 200 words, no outdated info, actionable summary present90 - **Routine command:** every skill in the workflow table exists at the named path, all steps are numbered, output destination named91927. Use AskUserQuestion:93 - Question: "Do these quality criteria look right?"94 - Options: "These look good" / "Adjust some"95968. Use AskUserQuestion (separate step):97 - Question: "Which evaluation mode?"98 - Options: "Deterministic (checks things mechanically — structure, format, keywords)" / "AI Judge (LLM scores subjective quality — tone, authenticity, completeness)"991009. Use AskUserQuestion (separate step):101 - Question: "How many iterations? (5 recommended)"102 - Options: "5 (recommended)" / "10" / "20"103104---105106## Phase 1: Build the Eval System10710810. Spawn `autoresearch-eval-agent` with:109 - Target file path + contents110 - Confirmed criteria list111 - Session directory path112 - Eval mode (deterministic or ai_judge)113 - Output file extension114115 **Deterministic:** agent generates `eval.py` + `test_cases.json`116 **AI Judge:** agent generates `rubric.md` + `test_cases.json`11711811. Read the generated file (eval.py or rubric.md) and show it to the user. Use AskUserQuestion:119 - Question: "Does this eval capture what you mean?"120 - Options: "Looks good" / "Adjust it"121122 If adjust: spawn eval agent again with specific feedback.12312412. Once confirmed — **eval artifacts are READ-ONLY for the rest of the session.** Never modify eval.py, rubric.md, or test_cases.json during the loop.125126---127128## Phase 2: Baseline (Iteration 0)12913013. Spawn `autoresearch-test-runner` with:131 ```132 Execute the target file at [full path to target].133 Test cases are at [session directory]/test_cases.json.134 The working project is at [YOUR_PROJECT_PATH]. Replace with your actual absolute path before running.135136 Reference files the target depends on (read these first):137 - [list ALL files the target references: context/, brain/, design-kit/, etc.]138139 Use all available tools to produce real outputs.140 Save each output to [session directory]/outputs/output_00.[ext] through output_09.[ext].141 Follow the target exactly. One output per test case. No commentary.142 ```143144 IMPORTANT: Scan the target file for any file paths, references/ mentions, context/ reads, or [[wikilinks]] — list all of them explicitly in the prompt.14514614. Evaluate the baseline:147 - **Deterministic:** `python [session directory]/eval.py [session directory]/outputs/` — parse `METRIC pass_rate=X.XXXX`148 - **AI Judge:** Spawn `autoresearch-judge` with outputs/ + rubric.md — parse `quality_score` from `judge-scores.json`14915015. Record baseline in `autoresearch-log.jsonl`. Create initial dashboard from `references/dashboard-template.html`.151152---153154## Phase 3: The Loop155156Repeat for the chosen iteration count (stop early if metric plateaus for 10+ consecutive iterations or user says "stop"):157158### Step 1 — Review159- Read current target file160- Read last 5 entries from `autoresearch-log.jsonl`161- Read failure details from last eval (which assertions fail most? which test cases are hardest?)162- Read `autoresearch-ideas.md` if it exists163164### Step 2 — Ideate165- Pick ONE change to try. One hypothesis, one variable.166- Reason: target the weakest area from the last eval's assertion breakdown or rubric breakdown.167- Write the hypothesis in plain English before making the change.168169### Step 3 — Modify170- Copy target file to `[target-filename].backup` in the session directory171- Make EXACTLY ONE change to the target file172173### Step 4 — Execute (via Test Runner)174- Scan the updated target file for reference files again (they may have changed)175- Spawn `autoresearch-test-runner` with the same prompt as Phase 2, updated with any new reference file paths176177### Step 5 — Evaluate178- **Deterministic:** Run `python eval.py outputs/` — parse `METRIC pass_rate=X.XXXX`179- **AI Judge:** Spawn `autoresearch-judge` — parse `quality_score` from `judge-scores.json`180181### Step 6 — Decide182| Condition | Action |183|-----------|--------|184| Metric improved | KEEP — change stays, update `.backup` to new version |185| Metric same or worse | DISCARD — restore from `.backup` |186| Eval crashed | CRASH — restore from `.backup`, note the error |187188### Step 7 — Log + Dashboard189Append to `autoresearch-log.jsonl`:190```json191{"iteration": 1, "timestamp": "ISO", "hypothesis": "...", "metric_name": "pass_rate", "metric_value": 0.70, "baseline": 0.50, "best_so_far": 0.70, "delta": "+0.20", "eval_mode": "deterministic", "assertion_breakdown": {"assertion_1": 9, "assertion_2": 7}, "status": "keep"}192```193AI Judge format uses `"rubric_breakdown": {"criterion_1": 3.8, "criterion_2": 3.2}` instead.194195Update dashboard HTML with current stats.196197### Step 8 — Stuck Check198If 3+ consecutive discards on similar ideas → pivot radically. Try a completely different approach.199200---201202## Stopping203204When the loop finishes (iteration count reached, plateau, or user says "stop"):20520616. Write final summary to `autoresearch-worklog.md`:207 - Total iterations run208 - Best metric achieved vs baseline209 - Top 3 most impactful changes210 - Which criteria improved most211 - Untried ideas (from `autoresearch-ideas.md`)21221317. Show the user the improved target file. Use AskUserQuestion:214 - Question: "Write the improved version to [target path]?"215 - Options: "Yes, write it" / "Skip" / "Edit first"21621718. On confirmation: write the improved file to the original target path.21821919. Save dashboard to `inbox/outputs/html/YYYY-MM-DD-operations-autoresearch-[target-name].html`220 Save log to `inbox/outputs/json/YYYY-MM-DD-operations-autoresearch-[target-name].jsonl`221222---223224## Separation Rules2252261. **You are the optimizer. NEVER generate outputs, write eval code, or score quality yourself.**2272. **Eval artifacts (eval.py, rubric.md, test_cases.json) are READ-ONLY once confirmed.**2283. **Test runner NEVER sees the eval or rubric.** Fresh context every time.2294. **Judge NEVER sees iteration history.** Fresh context every time. (AI judge mode)2305. **You NEVER read eval.py source code or rubric scoring examples.** Only read the metric number.231232---233234## Edge Cases235236| Situation | What to do |237|-----------|-----------|238| User says "autoresearch" without a target | Ask: "Which file do you want to optimize? (skill name, CLAUDE.md, context/[file], brain/[moc], or /command name)" |239| Target file doesn't exist | Stop and flag: "I can't find [path]. Check the name and try again." |240| Eval.py crashes with syntax error | Spawn eval agent again with the error message. Fix before starting the loop. |241| Skill produces binary output (PDF, image) | Deterministic eval checks file exists + non-empty only. Flag to user that content-level scoring isn't available. |242| All 20 iterations discard | Show user the final summary with a note: "The criteria may be too strict or the target may need manual redesign first." |243| User messages during loop | Pause, respond, then offer to resume: "Want me to continue from iteration X?" |244| Target is operations-autoresearch itself | Skip gracefully — don't recurse. |245246---247248## What Good Looks Like249250The target file improves measurably across the iteration log. The dashboard shows a clear upward trend in the metric with the specific changes that drove each keep. The user sees a before/after and confirms. The session leaves a JSONL audit trail and dashboard in inbox/outputs/ for reference.