---
name: design-autopilot-batch
description: >
  Batch orchestrator above /design-generate. Pulls Ready UI tickets
  from GitLab, decides eligibility automatically (deterministic prefilter +
  Haiku commodity classifier + confidence threshold — no manual design::eligible
  label needed), then sequentially feeds /design-generate --auto until budget
  caps are reached. Each proto is rendered to a GitLab Pages URL posted on the
  ticket and the ticket is moved to design::review for the PM gate. Posts a
  summary to #tech-ci-agent-autopilot.
  Use when the user says /design-autopilot-batch, /design-batch, 'design batch',
  'autopilot design', 'lance le batch design', 'génère les protos en attente',
  'vide la queue design', 'traite les tickets UI prêts', 'génère tous les protos en attente',
  'design autopilot batch', 'drain the design queue', 'process the ready UI tickets',
  'batch the prototypes', 'generate all pending protos', or wants to drain commodity-UI
  tickets into review-ready prototypes without manual intervention. Distinct from
  /design-generate, which prototypes ONE ticket interactively — this is the unattended
  batch orchestrator that pulls many tickets and feeds them to /design-generate.
argument-hint: "[--project SHIFT] [--max-tickets N] [--threshold 70] [--dry-run] [--skip-llm-rank]"
allowed-tools:
  - Bash
---

Batch orchestrator: turn `workflow::Ready` commodity-UI tickets into review-ready HTML protos, fully automatically.

## How I work

**Inputs I need**
- Optional flags via `$ARGUMENTS`: `--project <slug>` (repeatable), `--max-tickets N`, `--threshold <0-100>` (Haiku eligibility confidence floor, default 70), `--dry-run`, `--no-slack`, `--skip-llm-rank` (deterministic eligibility only).
- Two runtime prerequisites NOT auto-validated, failing on the first LLM call: `ANTHROPIC_API_KEY` (or `ANTHROPIC_CI_AUTOPILOT_API_KEY`) set, and the `claude` CLI in `$PATH`.

**Auto-eligibility (no manual label)**
The batch decides on its own whether a ticket is a commodity UI feature, in two cheap-first tiers:
1. **Deterministic prefilter** — reject tickets with no UI signal, or with a custom-interaction keyword (drag-drop, livemap, animation, real-time, dataviz…). Free, no LLM call.
2. **Haiku classifier** — on survivors, judge `{commodity, confidence}`. Only `commodity AND confidence ≥ --threshold` is fast-pathed.
Manual labels remain as optional overrides: `design::eligible` forces in, `design::skip` forces out.

**What I produce**
- An ASCII table on stdout (one row per processed/skipped/escalated ticket) — emit as-is.
- A Slack thread on `#tech-ci-agent-autopilot` (suppressed by `--no-slack`).
- Exit code: `0` = all clean, `1` = ≥1 ticket escalated to `design::blocked`, `2` = technical failure.

**What I never do**
- Never call `AskUserQuestion`. Designed for unattended loops (`gstack /loop` or CI scheduled job).
- Never make direct GitLab/Slack/subprocess calls. Everything goes through `pysae-ai-tools agent design-run`.
- Never validate the proto myself — the **PM gate stays human** (review of `design::review` + the Pages URL). The autopilot only renders; it never sets `Validated`.
- Never auto-create the React PR. Handoff to `/code-implement` stays a separate, human-triggered step.

**When I delegate**
- Single delegation: `pysae-ai-tools agent design-run $ARGUMENTS`. The CLI calls `claude -p /design-generate <issue_url> --auto` as a subprocess per eligible ticket (`--auto` = no AskUserQuestion + emits the `DESIGN_RESULT` footer).

**When I escalate** (transitions a ticket to `design::blocked` with a comment)
- `/design-generate` returns `status: escalated` (oracle never CLEAN after 5 loops, no Pages render, defensive eligibility re-check failed…).
- WIP orphan reclaim: any ticket stuck in `design::wip` for more than 2h is forcibly moved to `design::blocked` at the start of the run.

**Common failures**
- `claude` absent from `$PATH` → exit 2, nothing processed.
- `ANTHROPIC_API_KEY` not exported → first eligibility call crashes; mitigate by running `--skip-llm-rank` first (deterministic eligibility only) to validate the pipeline.
- First run on a new project: start with `--dry-run --no-slack --skip-llm-rank --project <low-stakes>` to validate the pull + eligibility before any side effect.

## Required tools

- `glab`
- `claude` (CLI binary, used as subprocess for /design-generate)

Run `pysae-ai-tools tools require <tools>` before starting; if it exits non-zero, abort and report the install command from stderr to the user.

## What it does

Delegates the entire batch run to the deterministic CLI orchestrator. The CLI:

1. Detects current repo (or uses `--project` overrides).
2. Reclaims `design::wip` orphans (>2h) by escalating them to `design::blocked`.
3. Pulls `workflow::Ready` tickets, dropping those already carrying a `design::*` state label.
4. Runs the 2-tier auto-eligibility gate; skips non-eligible tickets (logged with the reason).
5. Ranks eligible tickets by deterministic business score, caps to `--max-tickets`.
6. Per ticket: marks `design::wip`, runs `/design-generate --auto`, then on success marks `design::review` + posts the Pages URL, on failure marks `design::blocked` + posts the reason.
7. Publishes the run report (stdout table + Slack).

## Usage

```bash
# Dry-run first (no side effects): see what would be picked and why
pysae-ai-tools agent design-run --project shift --dry-run --no-slack --skip-llm-rank

# Real run on shift, default threshold 70
pysae-ai-tools agent design-run --project shift

# Loop locally
gstack /loop 30m /design-autopilot-batch --project shift
```
