pi-autoresearch-loop
```markdown
What this skill does
```markdown
---
name: pi-autoresearch-loop
description: Autonomous experiment loop for pi that continuously tries optimizations, measures results, and keeps what works
triggers:
- autoresearch
- autonomous experiment loop
- optimize automatically
- run experiment loop
- continuous optimization
- benchmark and improve
- start autoresearch session
- keep what works discard what doesnt
---
# pi-autoresearch — Autonomous Experiment Loop
> Skill by [ara.so](https://ara.so) — Daily 2026 Skills collection
Autonomous experiment loop extension for [pi](https://github.com/antiwork/pi). Continuously proposes changes, benchmarks them, commits wins, reverts losses, and repeats — forever. Works for any measurable target: test speed, bundle size, build time, LLM training loss, Lighthouse scores.
---
## Installation
```bash
pi install https://github.com/davebcn87/pi-autoresearch
```
**Manual install:**
```bash
cp -r extensions/pi-autoresearch ~/.pi/agent/extensions/
cp -r skills/autoresearch-create ~/.pi/agent/skills/
```
Then `/reload` in pi.
---
## Quick Start
```
/skill:autoresearch-create
```
The agent will:
1. Ask about your goal, command, metric, and files in scope (or infer from context)
2. Create a branch
3. Write `autoresearch.md` and `autoresearch.sh`
4. Run the baseline
5. Start looping immediately — no further input needed
---
## Core Concepts
### Two-file persistence model
Every session is fully recoverable from two files:
| File | Purpose |
|------|---------|
| `autoresearch.jsonl` | Append-only log — one JSON line per run (metric, status, commit, description) |
| `autoresearch.md` | Living document — objective, what's been tried, dead ends, key wins |
A fresh agent with zero memory can read these two files and continue exactly where the previous session left off.
### Session files written by the skill
| File | Purpose |
|------|---------|
| `autoresearch.md` | Session document — objective, metrics, files in scope, experiment history |
| `autoresearch.sh` | Benchmark script — pre-checks, runs the workload, outputs `METRIC name=number` lines |
| `autoresearch.checks.sh` | *(optional)* Backpressure checks — tests, types, lint. Failures block `keep` |
---
## Extension Tools
### `init_experiment`
One-time session configuration. Call once at session start.
```typescript
await init_experiment({
name: "vitest-speed",
metric: "seconds",
unit: "s",
direction: "lower", // "lower" | "higher"
});
```
### `run_experiment`
Runs any shell command, times wall-clock duration, captures stdout/stderr.
```typescript
const result = await run_experiment({
command: "pnpm test --run",
timeout_seconds: 120, // optional, default 300
checks_timeout_seconds: 300, // optional, for checks script
});
// result: { exit_code, duration_seconds, stdout, stderr }
```
### `log_experiment`
Records result, auto-commits on `keep`, updates the status widget and dashboard.
```typescript
await log_experiment({
metric_value: 42.3,
status: "keep", // "keep" | "discard" | "crash" | "checks_failed"
description: "Enable parallel test workers in vitest config",
commit_message: "perf: parallel vitest workers → 42.3s (-18%)",
});
```
---
## The Autonomous Loop
Once started, the agent runs this cycle indefinitely:
```
propose change → edit files → run_experiment → measure metric
↓
metric improved?
YES → log_experiment(keep) → auto-commit → update autoresearch.md
NO → log_experiment(discard) → git revert → try next idea
↓
repeat forever (until interrupted)
```
**Interrupt anytime** with `Escape`, then ask for a summary of what was tried.
---
## Benchmark Script Format
`autoresearch.sh` must output at least one `METRIC` line:
```bash
#!/bin/bash
set -euo pipefail
# Pre-checks
[ -f package.json ] || { echo "No package.json"; exit 1; }
# Run workload
pnpm test --run
# Output metric — required format
echo "METRIC seconds=$SECONDS"
```
Multiple metrics are supported:
```bash
echo "METRIC duration_seconds=42.3"
echo "METRIC test_count=847"
echo "METRIC memory_mb=512"
```
The primary metric (set in `init_experiment`) drives keep/discard decisions. Others are recorded for analysis.
---
## Backpressure Checks (Optional)
Create `autoresearch.checks.sh` to guard correctness after every passing benchmark:
```bash
#!/bin/bash
set -euo pipefail
pnpm test --run # full test suite
pnpm typecheck # TypeScript
pnpm lint # ESLint / Biome
```
**Behavior:**
- File absent → loop runs exactly as before, no change
- File present → runs automatically after every benchmark that exits 0
- Checks time does **not** count toward the primary metric
- Checks failure → logged as `checks_failed`, changes reverted (same as crash)
- Dashboard shows `checks_failed` separately from `crash` so you can distinguish correctness failures from benchmark errors
---
## UI
### Status Widget
Always visible above the editor:
```
🔬 autoresearch 12 runs 8 kept │ best: 42.3s
```
### Dashboard
Open with `/autoresearch` — full results table with status, metric values, descriptions, and best run highlighted.
- `Ctrl+X` — toggle dashboard
- `Escape` — close dashboard / interrupt loop
---
## Example Domains
```typescript
// Test speed
{
command: "pnpm test --run",
metric: "seconds",
direction: "lower",
scope: ["vitest.config.ts", "src/**/*.test.ts"],
}
// Bundle size
{
command: "pnpm build && du -sb dist | cut -f1",
metric: "bytes",
direction: "lower",
scope: ["vite.config.ts", "src/index.ts"],
}
// LLM training loss
{
command: "uv run train.py --epochs 1",
metric: "val_bpb",
direction: "lower",
scope: ["train.py", "model.py", "config.yaml"],
}
// Build speed
{
command: "pnpm build",
metric: "seconds",
direction: "lower",
scope: ["tsconfig.json", "vite.config.ts"],
}
// Lighthouse performance
{
command: "lighthouse http://localhost:3000 --output=json | jq '.categories.performance.score'",
metric: "score",
direction: "higher",
scope: ["src/pages/index.tsx", "public/"],
}
```
---
## autoresearch.md Structure
The skill writes and maintains this file throughout the session:
```markdown
# autoresearch: vitest-speed
## Objective
Reduce test suite wall-clock time. Baseline: 51.7s.
## Metric
- Name: seconds
- Direction: lower is better
- Baseline: 51.7s
- Best so far: 42.3s (run 8)
## Files in scope
- vitest.config.ts
- src/**/*.test.ts
## What's been tried
- [kept] Run 8: Enable parallel workers → 42.3s (-18%)
- [discarded] Run 5: Increase pool size to 16 → 53.1s (+3%)
- [kept] Run 3: Disable coverage in CI → 47.8s (-8%)
## Dead ends
- Increasing pool beyond 8 causes memory pressure, net negative
## Next ideas
- [ ] Try forks pool instead of threads
- [ ] Investigate slow test files with --reporter=verbose
```
---
## autoresearch.jsonl Format
One JSON object per line:
```jsonl
{"run":1,"metric_value":51.7,"status":"keep","description":"baseline","commit":"a1b2c3d","timestamp":"2025-01-15T10:00:00Z"}
{"run":2,"metric_value":49.2,"status":"keep","description":"disable coverage","commit":"e4f5g6h","timestamp":"2025-01-15T10:03:21Z"}
{"run":3,"metric_value":53.1,"status":"discard","description":"increase pool to 16","commit":null,"timestamp":"2025-01-15T10:07:45Z"}
{"run":4,"metric_value":null,"status":"crash","description":"invalid vitest config syntax","commit":null,"timestamp":"2025-01-15T10:09:12Z"}
```
Read the log programmatically:
```typescript
import { readFileSync } from "fs";
const runs = readFileSync("autoresearch.jsonl", "utf-8")
.trim()
.split("\n")
.map((line) => JSON.parse(line));
const kept = runs.filter((r) => r.status === "keep");
const best = kept.reduce((a, b) =>
a.metric_value < b.metric_value ? a : b
);
console.log(`Best: ${best.metric_value} — ${best.description}`);
```
---
## Resuming a Session
The agent can resume from either file. Recommended resume prompt:
```
Read autoresearch.jsonl andRelated in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.