# Plan-execution queue

Gitea-backed work queue that drives the per-driver implementation plans (`docs/plans/*-plan.md`) to completion in **Mode B** (autonomous: auto-merges into the `auto/driver-gaps` integration branch when build+tests pass).

## Pieces

- `pr-manifest.yaml` — canonical list of every PR across all six plans.
- `setup-labels.sh` — idempotently creates the queue labels in Gitea.
- `file-issues.sh` — files one Gitea issue per manifest entry (idempotent — skips ids that already exist).
- `next-pr.sh` — picks the next eligible queue issue (queued, blockers all done) as JSON.
- `start-pr.sh ISSUE BRANCH` — flips queued → in-progress and creates the branch off `auto/driver-gaps`.
- `open-pr.sh ISSUE BRANCH TITLE BODY_FILE` — opens a PR from BRANCH into `auto/driver-gaps`.
- `merge-pr.sh PR` — merges a PR with branch-delete (Mode B).
- `finish-pr.sh ISSUE success PR` / `finish-pr.sh ISSUE failed REASON_FILE` — closes / marks failed.

## Flow per loop iteration

1. `next-pr.sh` → issue#, branch, canonical id.
2. `start-pr.sh` → mark in-progress, create branch.
3. Loop driver dispatches a Claude Agent to implement the PR on the branch.
4. Loop runs `dotnet build` + `dotnet test`.
5. On green: `open-pr.sh`, `merge-pr.sh`, `finish-pr.sh success`.
6. On red: capture log → `finish-pr.sh failed log.txt`. Issue stays open with `queue/failed` label for retry.

## Environment

- Gitea repo: `dohertj2/lmxopcua` on `gitea.dohertylan.com`.
- Token: read from `%LOCALAPPDATA%\tea\config.yml` (or `$GITEA_TOKEN` override).
- Integration branch: `auto/driver-gaps` (created off master).
- Per-PR branches: `auto/<driver>/<plan-pr-id>`.

## Reset / debug

- Re-list eligible issues: `bash scripts/queue/next-pr.sh`.
- Manually unblock: remove `queue/blocked` label and add `queue/queued`.
- Drop a failed PR back into queue: remove `queue/failed`, add `queue/queued`.
