Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Autoresearch — Codebase Summary

AI-friendly reference for agents working on this codebase.

Entry Points

PathPurpose
src/main.rsCLI entry — Clap-based command dispatch for run setup, verify/guard/decide, health, resume/status/progress/watch, lessons, handoff, exec, runtime, parallel, screen, and hooks
.claude-plugin/marketplace.jsonClaude marketplace manifest for the repo-root plugin package
hooks/hooks.jsonClaude Code plugin hook definitions — maps lifecycle events to binary invocations
skills/autoresearch/SKILL.mdAgent skill file — iteration protocol, subcommand table, references
.agents/skills/autoresearch/Maintained Codex skill package used by direct Codex installs
plugins/autoresearch/Codex plugin package generated from the .agents skill package
.agents/plugins/marketplace.jsonLocal Codex marketplace entry pointing at plugins/autoresearch/
.opencode/Generated OpenCode commands and skill package, plus the maintained docs-manager helper agent
commands/autoresearch.mdRoot command protocol (core iteration loop)
commands/autoresearch/*.mdSubcommand protocols (debug, fix, security, scenario, etc.)

Core Modules (src/core/)

FileResponsibility
config.rsRunConfig, Direction, VerifyFormat, RollbackStrategy types
git.rsGitRepo wrapper — status, head, revert, worktree checks
verify.rsRun verify commands, parse scalar/JSON output, safety screening
results.rsResultsLog — append TSV rows, read history
state.rsRunState — iteration count, metrics, keeps/discards, phase tracking
metrics.rsMetric parsing, delta calculation, direction comparison
context.rsCanonical context.json and repo-local pointer writing
health.rsNative preflight checks for runtime launch safety
runtime.rsBackground launch/runtime manifests, supervisor snapshots, and stop control

Escalation (src/escalation/)

FileResponsibility
pivot.rsEscalationState — track consecutive discards, trigger REFINE/PIVOT/SEARCH/STOP
lessons.rsLessonsLog — read/write/search cross-run learning entries

Hooks (src/hooks/)

FileHookFires On
scout_block.rsscout-blockPreToolUse (Write/Edit/MultiEdit/Bash/Glob/Grep/Read) — blocks generated paths, Bash reads, and out-of-scope writes
privacy_block.rsprivacy-blockPreToolUse — blocks access to sensitive paths
dangerous_cmd.rsdangerous-cmd-blockPreToolUse (Bash) — blocks rm -rf, fork bombs, etc.
iteration_context.rsiteration-contextUserPromptSubmit — injects run state into agent context
dev_rules_reminder.rsdev-rules-reminderUserPromptSubmit — re-injects active protocol and code standards
simplify_gate.rssimplify-gateUserPromptSubmit — reminds agent of simplicity rule
stop_check.rsstop-checkStop — detects premature stop during active run
compaction_reanchor.rscompaction-reanchorPostCompact — re-injects critical state after context compaction
session_init.rssession-initSessionStart — detects interrupted runs
session_end.rssession-endSessionEnd — emits terminal notification and optional webhook summary
subagent_context.rssubagent-contextSubagentStart — passes run context to subagents

Modes (src/modes/)

Thin logic for mode-specific state (most protocol lives in markdown commands): loop_mode.rs, debug.rs, fix.rs, security.rs, scenario.rs, predict.rs, reason.rs, probe.rs, learn.rs, ship.rs, evals.rs, improve.rs, plan.rs

Agents (src/agents/)

FilePurpose
claude.rsClaude Code-specific integration helpers
codex.rsCodex CLI-specific integration helpers

Data Flow

User prompt → [hook: iteration-context injects state]
           → Agent reads state + TSV + git log
           → Agent makes ONE change
           → Agent calls: autoresearch verify --command "..."
           → Binary runs command, returns metric + metrics JSON
           → Agent calls: autoresearch decide --decision auto --metric N --metrics-json '{...}'
           → Binary: evaluates criteria, updates state.json, appends TSV, reverts if discard
           → [hook: stop-check ensures agent doesn't quit early]
           → Next iteration

Background runs route the same state machine through autoresearch runtime run, which writes launch.json, runtime.json, and runtime.log, runs the native health preflight at each relaunch boundary, and supervises detached Codex turns. Parallel batches use autoresearch parallel prepare/run/closeout/cleanup to run worker worktrees and retain only one verified batch winner.

Key Types

TypeLocationFields
RunConfigcore/config.rsverify, direction, format, scope, guard, primary_metric_key
RunStatecore/state.rsiteration, baseline_metric, current_metric, best_metric, keeps, discards, crashes, consecutive_discards, phase
ResultRowcore/results.rsiteration, commit, metric, delta, guard, status, description
LaunchManifestcore/runtime.rsworkspace_root, execution_policy, codex_bin, repo_targets, config
EscalationStateescalation/pivot.rsconsecutive_discards, pivots, last_action
Directioncore/config.rsHigher, Lower
IterationStatuscore/state.rsBaseline, Keep, Discard, Crash, NoOp, Blocked, Pivot, Refine, Search

How to Add…

A new CLI command

  1. Add variant to Commands enum in src/main.rs
  2. Add match arm in main() dispatching to cmd_<name>() function
  3. Implement function at bottom of main.rs (or extract to module if >100 lines)

A new hook

  1. Add handler in src/hooks/<name>.rs
  2. Register in src/hooks/mod.rs
  3. Add hook entry in hooks/hooks.json under the appropriate lifecycle event
  4. Hook receives JSON on stdin, returns JSON on stdout, must complete in <5ms

A new mode/subcommand

  1. Add command protocol in commands/autoresearch/<mode>.md
  2. Add mode-specific state logic in src/modes/<mode>.rs (if needed)
  3. Register in src/modes/mod.rs
  4. Update SKILL.md subcommand table