---
name: code-autopilot-batch
description: >
  Batch orchestrator above /code-auto-pilot. Pulls agent::ready tickets from
  GitLab, scores them deterministically + Haiku LLM signal, then sequentially
  feeds /code-auto-pilot until budget caps are reached. Posts a summary to
  #tech-agent-autopilot.
  Use when the user says /code-autopilot-batch, /batch, 'autopilot batch',
  'vide la queue agent', 'process the agent queue', or wants to drain ready
  tickets without manual intervention.
argument-hint: "[--project SHIFT] [--project DRIVER] [--max-tickets N] [--dry-run]"
allowed-tools:
  - Bash
---

Batch orchestrator: drain agent::ready tickets across one or more Pysae repos.

## Required tools

- `glab`
- `claude` (CLI binary, used as subprocess for /code-auto-pilot)

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 WIP orphans (>2h) by escalating them to `agent::blocked`.
3. Pulls all `agent::ready` issues across the configured projects.
4. Filters out tickets matching the regex sensitive-paths pass (auth, secrets, infra, DB migrations) unless `agent::override-sensitive` is set.
5. Scores remaining tickets: business score (priority + type + age) × LLM-assessed `success_probability` (Haiku 4.5).
6. Filters out tickets the LLM flagged `sensitive_domain_match` unless override.
7. Caps to `--max-tickets` and processes them sequentially via subprocess `claude /code-auto-pilot <issue_url>`.
8. Transitions labels: `agent::ready` -> `agent::wip` at pickup, then `agent::wip` -> cleared on success or `agent::blocked` on escalation (with comment).
9. Reports to stdout (table) and Slack `#tech-agent-autopilot` (per-ticket + summary).

## Invocation

Just delegate to the CLI. Pass through all arguments from `$ARGUMENTS`:

```bash
pysae-ai-tools agent run $ARGUMENTS
```

## Modes

- **Local one-shot**: `claude /code-autopilot-batch` (defaults to current repo)
- **Multi-repo**: `claude /code-autopilot-batch --project shift --project driver`
- **Loop locale**: `gstack /loop 15m /code-autopilot-batch` (relance toutes les 15 min)
- **CI scheduled**: pipeline scheduled GitLab utilisant le template `.ai-tools-skill` qui invoque `claude /code-autopilot-batch`

## Exit codes (propagated by the CLI)

- `0`: tout traité avec succès, zéro escalade
- `1`: >= 1 ticket escaladé en `agent::blocked` (utile pour faire échouer le job CI scheduled)
- `2`: erreur technique (GitLab API down, `claude` binary absent, etc.)

## Critical rules

- **Délégation pure**: ne jamais faire d'appels GitLab, Slack, ou subprocess ici. Tout passe par `pysae-ai-tools agent run`.
- **Pas d'AskUserQuestion**: le skill est conçu pour tourner sans humain (ni en local en boucle ni en CI scheduled).
- **Output structuré**: la CLI imprime un tableau ASCII en fin de run, à laisser tel quel sans reformater.

$ARGUMENTS
