Metadata-Version: 2.5
Name: procyon-worker
Version: 0.1.3
Summary: Autonomous worker for eic/Procyon: launches AI coding agents that implement, repair and review ePIC analysis workflows
Project-URL: Homepage, https://github.com/eic/ProcyonWorker
Project-URL: Documentation, https://github.com/eic/ProcyonWorker/tree/main/docs
Project-URL: Source, https://github.com/eic/ProcyonWorker
Project-URL: Issues, https://github.com/eic/ProcyonWorker/issues
Project-URL: Changelog, https://github.com/eic/ProcyonWorker/releases
Author: Wouter Deconinck
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: ai-agents,automation,claude,codex,eic,epic,physics-analysis,reproducibility,snakemake
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: >=3.11
Requires-Dist: rich>=13
Requires-Dist: textual<9,>=8
Description-Content-Type: text/markdown

# Procyon Worker

`procyon` is the worker for [Procyon](https://github.com/eic/Procyon), the
repository in which AI agents implement the analysis plans of
[ProcyonAnalyses](https://github.com/eic/ProcyonAnalyses) as Snakemake workflows
that run in a pinned container. It uses a "bring your own agent" approach. Run it
with no command and you get a dashboard of the work the queue needs right now:
pull requests to review, fixes a review asked for, a `plans.lock` that is behind,
plan targets nobody has implemented. From there you launch whatever you want. Pin
a worker to one kind of work with `--only` (a reviewer, a fixer, an author), or
hand the whole thing to `--loop` and let it pick the most useful job each round
until you stop it.

> **Status.** This is a fork of
> [EpsilonEridaniWorker](https://github.com/eic/EpsilonEridaniWorker), adapted to
> Procyon; [docs/upstream.md](https://github.com/eic/ProcyonWorker/blob/main/docs/upstream.md) says what is the same and what
> differs. **It has not yet run a real round against `eic/Procyon`.** Its test
> suite passes and its commands start, but no agent launched by it has opened,
> fixed or reviewed a pull request there, and its queries have not been run
> against that repository's live queue. Expect to find faults on the first rounds,
> and watch them.

It runs as your authenticated `gh` account: you set up `gh auth`, the worker acts
as that account, and it treats that account's own PRs as the ones it tends. The
repo is hardwired to `eic/Procyon`. This is an operator's tool for that
project, not a general framework. You author through **your own fork**: the worker
forks `eic/Procyon` once, automatically, pushes authored branches and
fixes there, and opens PRs from it, so you do **not** need write access to the
canonical repo. (A fine-grained token scoped only to the canonical repo is not
enough.) Set `PROCYON_FORK=<owner>/<repo>` to use an existing fork instead.

Run as many workers as you like: they take a lease on each job so two of them
never fix the same PR or open the same bump, and that needs no setup and no
write access either. The leases live in your fork, so they coordinate your own
workers. Two operators' fleets see each other's leases only in the shared
namespace, [eic/procyon-claims](https://github.com/eic/procyon-claims): a worker
uses it once its account has push access there, which a maintainer grants by
hand, and claims in its fork until then. See
[the claim namespace](https://github.com/eic/ProcyonWorker/blob/main/docs/reference.md#the-claim-namespace).

Nothing here merges a pull request. Procyon has no auto-merge; a human merges.

## Quickstart

You need `gh`, `git`, `uv`, and `jq`. Log `gh` in as the account the worker
should act as, and log in to each subscription agent you want to use:

```bash
gh auth login
codex login            # for --agent codex, or auto
claude auth login      # for --agent claude, or auto
kiro-cli login         # for explicit --agent kiro
```

A round that writes code runs the analysis in the container its plan pins, so
the host also needs a container runtime: `apptainer`, `docker` or `podman`. The
worker uses the first of those on `PATH`, or the one `PROCYON_CONTAINER_RUNTIME`
names, and refuses a code-writing round when there is none. See
[where analyses run](https://github.com/eic/ProcyonWorker/blob/main/docs/reference.md#where-analyses-run) for that and for the
Apptainer cache and Slurm settings. Under Apptainer the image comes from CVMFS
when `/cvmfs/singularity.opensciencegrid.org` holds the copy the plan pins, and
is built from the registry otherwise (about 14 GB and twelve minutes, once);
`PROCYON_IMAGE_SOURCE=auto|cvmfs|registry` chooses, and `procyon doctor` says
whether CVMFS is readable. The OpenRouter agents need an exported
`OPENROUTER_API_KEY` instead of a login, plus the `pi` runner.

Install it as a tool, no clone needed. **No release has been published yet**, so
for now the install is from the repository:

```bash
uv tool install git+https://github.com/eic/ProcyonWorker
```

Once a release exists the install is `uv tool install procyon-worker` (the
distribution is `procyon-worker`; the command it installs is `procyon`, and the
PyPI project named `procyon` is somebody else's). Publishing needs a human, once:
register the PyPI trusted publisher (project `procyon-worker`, repository
`eic/ProcyonWorker`, workflow `publish.yml`) and push a `v*` tag. Then:

```bash
procyon doctor                     # report the tools and credentials this host can use
procyon                            # the dashboard: see the available work, launch it
procyon status                     # the same survey, non-interactive (--json for scripts)
procyon usage --json               # prompt-free Kiro/OpenRouter credit telemetry
procyon work --only review         # one round of a specific kind of work, then exit
procyon work --loop --only review  # a focused worker: keep reviewing (or fix / analysis / ...)
procyon work --loop                # fully automatic: keep picking the most useful job
```

Ctrl-C stops the current round and exits. From a clone you can run `./procyon`
instead, a small PEP 723 `uv` shim that runs the same package; every command
below works either way, and this README writes the installed form.

## The dashboard

Bare `procyon` opens an interactive dashboard ([Textual](https://textual.textualize.io/)).
The table lists each kind of work with a number, how many PRs are ready, and a
sample. The survey is fetched once in the background and refreshed on `r` (or
every 90s), so moving the cursor never re-queries GitHub. It reacts to single
keypresses, no Enter:

| Key | Action |
|-----|--------|
| `↑` / `↓` (or `k` / `j`) | move the cursor between kinds |
| `→` / `←` | expand / collapse the selected kind — list its PRs with titles (or, on `analysis`, the areas) |
| `Enter` | run one round of the selected kind |
| `1`–`6` | run one round of that numbered kind directly |
| `l` / `L` | add a persistent worker for the auto cascade / selected kind |
| `o` / `x` | pick the single plan area (`--analysis-only`) / edit the skipped areas (`--analysis-skip`) |
| `m` | cycle the agent |
| `s` | the sandbox dial: fixed on the host, and says why (see [the sandbox notes](https://github.com/eic/ProcyonWorker/blob/main/docs/sandbox.md)) |
| `w` | switch between available Work and desired/actual Workers |
| `r` / `c` / `q` | refresh / copy the launch command to the clipboard / quit |

In the Workers view, arrows select a worker, Space persists enabled/disabled
desired state, Ctrl-R restarts it, and Enter follows its current logfile.

Your agent and area selections persist in `dashboard.json` under
the Procyon config directory, so the dashboard reopens where you left it. They
are dashboard-only: a bare `procyon work` never reads them, and an explicit
`PROCYON_ANALYSIS_ONLY` or `PROCYON_ANALYSIS_SKIP` in the environment still wins.
Clone-based and installed invocations share this user-level file. Over a pipe or
with no TTY the dashboard prints a one-shot snapshot instead. Use `procyon
status` in scripts.

## What a round does

A round does exactly one unit of work: the first of these that applies.

| Step | What it does |
|------|--------------|
| **Rebase** | Reconcile one of our PRs that conflicts with `main`. Limited by a per-PR attempt cap; a `keep`, `hold`, `wip`, `human` or `do-not-close` label pauses it. |
| **Bump** | Keep `plans.lock` current. Repair our red `bump-plans/` PR; or, when the pin on `main` is behind `main` of the plans repository and no bump PR is open, open one that moves the pin and brings every analysis whose plan changed into line with it. |
| **Fix CI** | Repair one of our PRs whose `build`, `analyses` or `reproduce` check is red. It cannot be reviewed until those pass, so this comes before Fix. |
| **Fix** | Address the review findings on one of our PRs: fix the code, or contest a wrong finding on its thread. |
| **Review** | Review an open PR whose head is green but not yet reviewed, with the `procyon-review` engine. Maintenance on our own PRs takes priority, so it cannot be starved by unrelated reviews. |
| **Analysis** | Otherwise, open a new PR implementing one target of a plan that is `active` at the commit `plans.lock` pins. |

Every code-writing round ends the same way before it pushes: the agent runs
`python3 scripts/run_analysis.py <Area>/<AnalysisName> --sample ci` in the
checkout, which runs the analysis in its container and compares the tables with
the committed `reference/ci/`. The `full` sample, the one that discharges a
target, is not a stage and no agent runs it.

Review selection is cooperative across workers. The worker named by
the latest scoreboard gets a 20-minute first-refusal window on that PR's next
green head or contest reply. After that window, every worker may take it;
eligible reviews are chosen by an age-weighted lottery, with waiting-time weight
capped after 24 hours so older work is favored without imposing a rigid queue.

### Interrupted rounds

A PR round (rebase, bump repair, fix CI, fix) commits and pushes from inside
the agent. When the agent is cut off first (the 5-hour limit, the round timeout, a
stopped service), the next round keeps what it left: its commits on top of the PR
head, plus any uncommitted edits as one WIP commit, go into a git bundle under
`$PROCYON_SALVAGE_DIR` (default `<install>/state/salvage`). The PR's next
round, on any worker of the install, replays them onto the PR head if the PR
has not moved since, with the edits back as edits, and tells the agent what it is
resuming. If the PR moved, the work is set aside in `superseded/` rather than
replayed. A round that exits 0 is never salvaged.

Merging, closing stuck PRs and de-duplicating are not the worker's job, and in
Procyon nothing automatic does them either: a human merges. A GitHub API failure
aborts the round rather than reading as "nothing to do", so a transient outage
never falls through to authoring.

A review has one output: the head-pinned scoreboard and the per-rubric threads
posted on the PR. They are posted under your own `gh` login, because the review
bot the engine names by default is not an existing GitHub App. The upstream
worker also published each review's records to a data repository; Procyon has
none, and nothing is archived.

## Configure a round

Four independent dials: which work, which pull requests, which agent, and where
it runs. Combine them however you like.

### What work: `--only`

With no `--only`, a round walks the whole cascade and does the first job that
applies. `--only <task>[,<task>...]` pins it to particular kinds, and `--skip`
drops kinds from the cascade (the two combine by subtraction):

```bash
procyon work --loop --only review     # only review open PRs
procyon work --loop --only fix,fix-ci # only tend to our own PRs
procyon work --loop --skip analysis    # everything except authoring new PRs
```

Analysis rounds steer toward one area: a directory under `ProcyonAnalyses/` in
the [plans repository](https://github.com/eic/ProcyonAnalyses), such as
`Inclusive` or `SemiInclusive`. A plan is `<Area>/<AnalysisName>`.

- `--analysis-only <area>` pins it. An empty value means all areas. With nothing
  set, each round picks a fresh random area among those that hold a plan with
  `status: active` at the commit `plans.lock` pins, so an unpinned `--loop` roams
  all of them over time. A round for an area without such a plan, or when no
  plan is active at all, ends before an agent is launched.
- `--analysis-skip <area>[,<area>...]` excludes areas from both the random pick
  and the all-areas case. `--analysis-only` wins on overlap.
- `--source <path-or-url>` gives the agent an existing repository to read, and
  needs the analysis phase enabled plus one pinned area. It is reference
  material: the agent implements the plan as written, every value still comes
  from the plan, and only then may it adapt compatible code from the source.

```bash
procyon work --only analysis --analysis-only Inclusive --source ../earlier-study
```

Analysis workers also avoid targets other contributors have announced in an
Intention issue of the plans repository (an open issue labelled `intention`,
held by its assignees, or by its author when it has none). Adjust with
`--analysis-extra-identities` (logins that count as your own side) or turn it
off with `--ignore-claims`; see [the reference](https://github.com/eic/ProcyonWorker/blob/main/docs/reference.md).

### Which PRs: `--pr`

A round normally picks its own target off the queue. `--pr <n>[,<n>...]` (repeat
the flag, or pass a comma list; a leading `#` is fine) points it at particular
pull requests instead:

```bash
procyon work --pr 412                  # whatever the cascade wants to do to #412
procyon work --pr 412,415 --only fix   # only those PRs, and only the fix unit
procyon work --pr 412 --dry-run        # what it would do to #412, doing nothing
```

`--pr` only ever *removes* work. It cannot make a PR actionable that the round
had already passed over, so a spent attempt budget, a peer's in-progress review,
the daily review cap and the branch claims all still hold: "work on these PRs"
means "of the work you were already willing to do, only this". An analysis
round, and the opening of a bump PR, name no existing PR, so a targeted round
drops them rather than quietly authoring something unrelated when the named PRs
turn out to have nothing to do, and it makes no GitHub writes at all about PRs you did not name —
not even the tracking issue an untargeted round files for a PR whose review
keeps erroring.

An empty or unreadable value is an error, not "no targeting": `--pr ""` and
`--pr 4 12` both stop the round rather than quietly turning it back into a
free-running worker.

That case — nothing to do — is the one worth knowing about, so the round says
why, one line per PR you named, before it exits without progress:

```
--pr: this round considers only #412, #415
  --pr #412: fix: reviews at head are all green
  --pr #415: review: daily cap 3/3 reached
```

`$PROCYON_PR` is the environment equivalent, which is how a
[managed worker](https://github.com/eic/ProcyonWorker/blob/main/docs/workers.md) gets one through its `env` table. Under
`--loop` the targeting is re-applied every round, so a targeted loop backs off
rather than wandering onto other work.

### Which agent: `--agent`

`--agent` is independent of `--only`, so any kind of work can run on any agent:

| `--agent` | Model | Billing |
| --- | --- | --- |
| `auto` (default) | Codex (`gpt-6-sol` → Luna if unavailable, high) preferred; Claude (`claude-opus-5-5`, high) fallback | subscription, paced |
| `codex` | `gpt-6-sol`, high effort; Luna fallback if Sol is unavailable | subscription, paced |
| `claude` | `claude-opus-5-5`, high effort | subscription, paced |
| `kiro` | `gpt-5.6-sol`, high effort by default; exact `claude-opus-5` opt-in | subscription credits, unpaced |
| `deepseek` | `deepseek/deepseek-v4-pro` via OpenRouter + [`pi`](https://github.com/badlogic/pi-mono) | pay-per-token (`OPENROUTER_API_KEY`) |
| `minimax` | `minimax/minimax-m3` via OpenRouter + `pi` | pay-per-token (`OPENROUTER_API_KEY`) |

Set a default with `PROCYON_AGENT`. Kiro and the OpenRouter agents are unpaced
and never run on their own; you have to ask for them by name. Kiro always passes
an exact model ID and first checks that the logged-in account advertises it—its
Auto router is never used. For example:

```bash
procyon work --agent kiro                              # exact gpt-5.6-sol
procyon work --agent kiro --author-model claude-opus-5
```

Run `kiro-cli chat --list-models --format json` to see which exact IDs your
account currently has. `KIRO_API_KEY` is supported for headless runs; when set,
Procyon isolates Kiro's browser-login store so the persisted login cannot take
precedence over the key.

For an explicit provider, `--author-model` and `--author-effort` override the
profile for one run. Pinning a Codex model also disables the automatic Luna
fallback. Every authoring launch prints its effective provider, model, effort,
and sandbox.

### Credit telemetry

`procyon usage` reads Kiro subscription credits and OpenRouter balances without
sending a model prompt. It is observability only and never changes provider
selection or loop pacing:

```bash
procyon usage --provider kiro
procyon usage --provider openrouter --json
procyon usage --kiro-burn-rate 2.4 --openrouter-burn-rate 1.50
```

The optional burn rates estimate rounds remaining. Kiro is queried through its
ACP `usage` command and fractional `used`/`limit` values are preserved. An
`OPENROUTER_API_KEY` reports its own usage and limit; additionally set an
`OPENROUTER_MANAGEMENT_KEY` to report account-wide purchased credits and usage.

### Which account: `--account`

Procyon spends whatever account the agent CLIs are already logged into. If you
have several ChatGPT accounts and care which one pays, `--account` makes that
explicit:

```bash
procyon doctor                 # shows which Codex account the credential is for
procyon work --agent codex --account you@example.com
```

It is a check, never a switch: a credential for a different account exits the
round before spending anything. Codex only, because its credential carries the
account identity and `codex login status` will not show it. To run Procyon on one
account while your interactive `codex` keeps another, give it a private
credential directory with `CODEX_HOME`; see
[the reference](https://github.com/eic/ProcyonWorker/blob/main/docs/reference.md#codex-accounts).

### Where it runs: the host

Every round runs its agent directly on the host, with your credentials and your
network. Keep that in mind when a round reads a pull request from an author you
do not trust: a review round does exactly that.

The upstream worker can instead run a round inside a
[bubble](https://github.com/kim-em/bubble) container. That sandbox is built
around a Lean toolchain image and has not been adapted for Procyon, where the
round itself has to start a container, so `--bubble` is refused before any work
starts. See [the sandbox notes](https://github.com/eic/ProcyonWorker/blob/main/docs/sandbox.md).

The agent's conversation transcript is normalized into readable narration,
reasoning summaries, tool activity, and results. File edits are listed by path
instead of repeating full diffs; tool inputs are bounded, and tool results over
64 KiB keep their first and last 32 KiB with an omitted-byte marker. Raw thinking
is never included. A round redirects this transcript to a timestamped file under
`logs/` and prints the path, tailing it if the agent exits non-zero. Pass
`--stream` to watch the identical transcript live instead.

## Persistent workers

Persistent workers are declarative and do not belong to a terminal session. You
describe what you want, and a manager keeps reality matching it. Nothing needs to
exist first:

```bash
procyon workers add                        # an enabled worker01, the whole cascade
procyon workers add reviewer --only review # a focused, named worker
procyon workers                            # desired and actual state
procyon workers logs --follow reviewer     # its durable console log
```

`add` writes the definition to `workers.toml`, under
`$XDG_CONFIG_HOME/procyon/` or the platform default, and starts a manager. From
there, `enable`, `disable`, `restart`, and `remove` adjust one worker each. The
manager validates the whole file before applying it, starts missing enabled
workers, gracefully stops disabled or removed ones, restarts only definitions
that changed, and backs off repeated failures.

For fields that `add` does not expose, run `procyon workers edit`, validate with
`procyon workers apply --check`, then apply. Editing while the manager runs is
safe: it keeps the last valid generation if the new file fails validation. A
later `enable`, `disable`, `add`, or `remove` rewrites the file canonically and
drops comments and hand formatting.

`workers apply` starts a detached manager for the current login session. To hand
an existing manager over to a native user service that survives logout and
returns after a reboot:

```bash
procyon workers manager-stop --leave-workers
procyon workers service install
procyon workers service status
```

This installs a systemd user service on Linux or a LaunchAgent on macOS. Omit
the first command when no detached manager is running.

Every worker needs a unique id, which `add` assigns for you. The id namespaces
that worker's state, checkout, review store, and logs, and isolates its mutable
agent credentials where the platform allows, so credential refreshes don't race.
Workers coordinate through GitHub rather than through each other, so adding
workers adds throughput. Ad-hoc rounds take the same id through
`procyon work --worker-id alice`.

[The workers documentation](https://github.com/eic/ProcyonWorker/blob/main/docs/workers.md) has the full `workers.toml` schema,
every action, the credential isolation rules, and the tmux viewer.

## Pacing against quota

`procyon` paces Codex and Claude against their session and weekly subscription
limits with no setup beyond logging in with the official CLIs. A provider is
available only while its used percentage is strictly below the budget for the
elapsed fraction of every reported window; `--agent auto` prefers Codex, to spare
the scarcer Opus, falls back to Claude, and sleeps when neither has room. A
provider held back by the pace line wakes when the rising budget overtakes its
usage, which is normally well before the window resets. Usage it cannot read
counts as unavailable rather than free. The dashboard and `procyon status` show
current usage and why a provider is waiting.

| Control | Effect |
| --- | --- |
| _(default)_ | The curve `60:40`: 40% of the quota by 60% of the window, then a ramp to the full quota by the reset. Holds a reserve for work that arrives late in a window |
| `--pace 0:10,50:70,90:90` | Use a different piecewise-linear `time%:budget%` curve: 10% allowed immediately, ramping to 70% by halfway and 90% at 90% of the window, interpolated between points. Usage must remain strictly below the current budget. Budgets ≥ 100 mean no soft cap; a window at 100% used still backs off |
| `--pace 0:0,100:100` | Spend at clock rate: the plain `used% < elapsed%` rule, which was the default before |
| `--ignore-quota` | Ignore soft pacing for an explicit `--agent codex` or `--agent claude`; hard limits still apply |
| `--quota-cmd CMD` | Your own pacer, run as `<cmd> <agent>`: the first stdout token is the model to run; empty output means wait |

`PROCYON_PACE` and `PROCYON_QUOTA_CMD` set the corresponding controls by
default. After a Claude window resets, `procyon` may make one small request to
start its usage clock, but only after it has found work and confirmed the other
window has room.
[The quota notes](https://github.com/eic/ProcyonWorker/blob/main/docs/quota.md) cover credential sources, the macOS Keychain,
and that bootstrap in detail.

## Further documentation

- [Relation to EpsilonEridaniWorker](https://github.com/eic/ProcyonWorker/blob/main/docs/upstream.md): what this fork keeps,
  what it changes, what is not available yet, and how to port an upstream change.
- [Persistent workers](https://github.com/eic/ProcyonWorker/blob/main/docs/workers.md): the `workers.toml` schema, every
  `procyon workers` action, state on disk, and running past logout.
- [`procyon work` reference](https://github.com/eic/ProcyonWorker/blob/main/docs/reference.md): every flag and environment
  variable, the container runtime settings, and the claim namespace.
- [Quota and pacing](https://github.com/eic/ProcyonWorker/blob/main/docs/quota.md): credential sources, Claude's two windows,
  and the window bootstrap.
- [The sandbox](https://github.com/eic/ProcyonWorker/blob/main/docs/sandbox.md): why `--bubble` is refused here.
- [Stuck review diagnostics](https://github.com/eic/ProcyonWorker/blob/main/docs/stuck-review-diagnostics.md): what a worker
  reports when a review keeps failing.
