AI-friendly reference for agents working on this codebase.
Path Purpose
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.)
File Responsibility
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
File Responsibility
pivot.rsEscalationState — track consecutive discards, trigger REFINE/PIVOT/SEARCH/STOP
lessons.rsLessonsLog — read/write/search cross-run learning entries
File Hook Fires On
scout_block.rsscout-block PreToolUse (Write/Edit/MultiEdit/Bash/Glob/Grep/Read) — blocks generated paths, Bash reads, and out-of-scope writes
privacy_block.rsprivacy-block PreToolUse — blocks access to sensitive paths
dangerous_cmd.rsdangerous-cmd-block PreToolUse (Bash) — blocks rm -rf, fork bombs, etc.
iteration_context.rsiteration-context UserPromptSubmit — injects run state into agent context
dev_rules_reminder.rsdev-rules-reminder UserPromptSubmit — re-injects active protocol and code standards
simplify_gate.rssimplify-gate UserPromptSubmit — reminds agent of simplicity rule
stop_check.rsstop-check Stop — detects premature stop during active run
compaction_reanchor.rscompaction-reanchor PostCompact — re-injects critical state after context compaction
session_init.rssession-init SessionStart — detects interrupted runs
session_end.rssession-end SessionEnd — emits terminal notification and optional webhook summary
subagent_context.rssubagent-context SubagentStart — passes run context to subagents
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
File Purpose
claude.rsClaude Code-specific integration helpers
codex.rsCodex CLI-specific integration helpers
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.
Type Location Fields
RunConfigcore/config.rs verify, direction, format, scope, guard, primary_metric_key
RunStatecore/state.rs iteration, baseline_metric, current_metric, best_metric, keeps, discards, crashes, consecutive_discards, phase
ResultRowcore/results.rs iteration, commit, metric, delta, guard, status, description
LaunchManifestcore/runtime.rs workspace_root, execution_policy, codex_bin, repo_targets, config
EscalationStateescalation/pivot.rs consecutive_discards, pivots, last_action
Directioncore/config.rs Higher, Lower
IterationStatuscore/state.rs Baseline, Keep, Discard, Crash, NoOp, Blocked, Pivot, Refine, Search
Add variant to Commands enum in src/main.rs
Add match arm in main() dispatching to cmd_<name>() function
Implement function at bottom of main.rs (or extract to module if >100 lines)
Add handler in src/hooks/<name>.rs
Register in src/hooks/mod.rs
Add hook entry in hooks/hooks.json under the appropriate lifecycle event
Hook receives JSON on stdin, returns JSON on stdout, must complete in <5ms
Add command protocol in commands/autoresearch/<mode>.md
Add mode-specific state logic in src/modes/<mode>.rs (if needed)
Register in src/modes/mod.rs
Update SKILL.md subcommand table