Skip to main content

Restart-on-exit supervisor for autonomous CLI agents

Project description

中文 · English

CI PyPI Downloads License codecov

agent-runner

A restart-on-exit supervisor for autonomous coding CLIs. Tested with Claude Code and aider out of the box; any prompt-arg CLI via custom config. Spawn the agent round-after-round under defenses that prevent the failure modes that bite in production: stuck rounds, orphan commits, OAuth burn loops, full disks, runaway memory.

┌──────────────────────────────────────────┐
│ Layer 3: The Witness (monitor)           │  11 detectors + auto-stop
├──────────────────────────────────────────┤
│ Layer 2: The Loop (serve, ~120 LOC)      │  signal-trapping restart loop
├──────────────────────────────────────────┤
│ Layer 1: The Round (round)               │  one agent invocation
└──────────────────────────────────────────┘

Install

pip install cli-agent-runner

The installed CLI command is agent-runner (the PyPI distribution name is prefixed for namespace disambiguation; the import name and command are not).

Quick start

cd your-project
agent-runner init                 # scaffold agent-runner.toml + prompts/main.md
$EDITOR agent-runner.toml         # point agent.command at your CLI
agent-runner install --monitor    # systemd user units for serve + monitor
agent-runner status               # confirm running
agent-runner peek                 # snapshot of project state
agent-runner monitor              # live anomaly detection

Full walkthrough: docs/quickstart.md.

16 verbs

Lifecycle Observation
init / install / uninstall peek — state snapshot
start / stop / kill / cancel watch — peek in a refresh loop
restart / status monitor — 11 detectors, alerts, auto-stop
round / serve / upgrade events — query / stream events.jsonl

Verb reference: docs/commands.md.

Defenses (built in)

11 named defenses, structured as data — see agent-runner peek --select defenses. Each carries the historical incident it codifies and the invariant test that guards it. Highlights:

  • round_timeout_s — hard wall, never the agent's word on when to stop
  • process_group_isolation — kill the round, not just the parent
  • orphan_stash_idempotency_s — no 3-stashes-per-second pile-ups
  • sha_locked_stashstash@{N} indices drift; SHAs don't
  • set_diff_classification — line-set comparison, not unified-diff +/- scan
  • startup_smoke_check — refuse to run with a clearly-truncated prompt

Full list and rationale: docs/architecture.md.

Monitor: 11 detectors

Notify only: timeout_rate, hung, orphan_chain, disk_warning, mem_pressure, smoke_fail_rate, network_fail, rate_limit_active, anomaly_repetitive_active.

Auto-stop the service (continuing is harmful):

  • oauth_fail — burning API quota on auth-rejected rounds
  • disk_critical — writing to a near-full disk risks corruption

Runs locally or against a remote host via ssh:

agent-runner monitor                  # local, 30s poll
agent-runner monitor --host pi        # remote, 60s poll
agent-runner monitor --json | jq -c   # pipe to downstream consumers

SSH trust boundary: monitor --host <alias> shells out via plain SSH using your local ~/.ssh/config (aliases, StrictHostKeyChecking behavior). A monitor with auto_stop enabled can issue agent-runner stop on the remote — verify your SSH config before pointing monitor at a remote service. See docs/runbook.md § "Remote monitor & SSH trust" for recommended hygiene.

Documentation

Development

git clone https://github.com/wan9yu/cli-agent-runner.git
cd cli-agent-runner
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"

./build.sh check                          # full local-CI sweep
./build.sh test                           # unit + integration only
AGENT_RUNNER_E2E_PI=1 ./build.sh e2e      # opt-in pi e2e (needs ssh alias `pi`)

Some docs/*.md blocks are generated from code — ./build.sh docs rewrites the <!-- gen:* --> regions, and ./build.sh check verifies they are fresh.

POSIX-only (Linux, macOS). Tested under Python 3.11+ on x86_64 and aarch64.

License

Apache License 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cli_agent_runner-0.1.35.tar.gz (278.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cli_agent_runner-0.1.35-py3-none-any.whl (108.0 kB view details)

Uploaded Python 3

File details

Details for the file cli_agent_runner-0.1.35.tar.gz.

File metadata

  • Download URL: cli_agent_runner-0.1.35.tar.gz
  • Upload date:
  • Size: 278.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cli_agent_runner-0.1.35.tar.gz
Algorithm Hash digest
SHA256 66990ee2db4f43d747461f4de6568d240633aa3a05616956cbbf11bf631dd402
MD5 090aa768a744b17d29599ac9f18815b7
BLAKE2b-256 9d113d9283c32e350fab5f8a0b7e480ea7ec57b2692074c175c22dd8a4004c7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cli_agent_runner-0.1.35.tar.gz:

Publisher: release.yml on wan9yu/cli-agent-runner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cli_agent_runner-0.1.35-py3-none-any.whl.

File metadata

File hashes

Hashes for cli_agent_runner-0.1.35-py3-none-any.whl
Algorithm Hash digest
SHA256 78e5bdb170b9f32f9948065532e75cbb8d310c5b99b35feb7a16bf3de0f16435
MD5 0add110600d8e5d9e8da1cbb4fe6b0ca
BLAKE2b-256 a62d69ca0749c72a381a6fbcc5a5aba3e547372c249a44c7288f9e5b7aabf7aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for cli_agent_runner-0.1.35-py3-none-any.whl:

Publisher: release.yml on wan9yu/cli-agent-runner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page