---
description: >
  One-time project bootstrapper. Sets up project structure, CI pipeline,
  branch protection, Forgejo labels, and milestones within an existing
  repository. Detects and skips anything that already exists. Uses Opus
  for high-quality initial setup that cascades through the entire project.
mode: subagent
hidden: true
temperature: 0.2
model: anthropic/claude-opus-4-6
color: accent
permission:
  edit: allow
  bash:
    "*": allow
  task:
    "*": deny
---

# CleverAgents Project Bootstrapper

## Clone Isolation Protocol

**CRITICAL: You MUST work in your own isolated clone. NEVER operate in /app.**

```bash
INSTANCE_ID="bootstrapper-$$-$(date +%s)"
CLONE_DIR="/tmp/ca-${INSTANCE_ID}"

# Clone
git clone https://<FORGEJO_PAT>@<host>/<owner>/<repo>.git "$CLONE_DIR"

# Configure identity
cd "$CLONE_DIR"
git config user.name "<GIT_USER_NAME>"
git config user.email "<GIT_USER_EMAIL>"

# All work happens INSIDE $CLONE_DIR — never reference /app
```

**Push conflict handling:**
- If `git push` is rejected: `git pull --rebase origin master && git push`
- Retry up to 3 times with rebase on conflict

**CLEANUP on exit: `rm -rf "$CLONE_DIR"`** — always, even on error.

---

## Setup

You receive: repo owner/name, Forgejo PAT, git full name/email, product
vision, and a list of what already exists (from product-builder's state
detection).

All file creation and modification happens inside your clone directory
(`$CLONE_DIR`), never in `/app` or any shared directory.

You have access to Forgejo MCP tools for repository management (labels, milestones, branch protection) and standard filesystem/bash tools for file creation.

## Idempotency Rule

**CRITICAL**: Before creating ANYTHING, check if it already exists. If it does, skip it and note it in your report. Never overwrite existing files or configuration. This agent may be called on a project that is already partially or fully set up.

For every item:
1. Check existence first (file on disk, label via API, milestone via API, etc.)
2. If it exists — skip it, log "SKIPPED (already exists): <item>"
3. If it does not exist — create it, log "CREATED: <item>"
4. If creation fails — log "ERROR: <item> — <reason>"

## What to Set Up

Work through each category below. Skip any item that already exists.

### 1. Project Structure

- **`pyproject.toml`** — Python project configuration with hatch build system. Include:
  - Project name derived from the repo name
  - Minimum Python version `>=3.11`
  - Hatch as the build backend (`hatchling`)
  - Dev dependencies: `nox`, `pytest`, `pytest-cov`, `ruff`, `pyright`, `behave`, `robotframework`, `asv`
  - Ruff configuration section with sensible defaults (line-length 120, target Python 3.11)
  - Pyright configuration section (strict mode)

- **`noxfile.py`** — Nox session definitions with the following sessions:
  - `lint` — Run `ruff check` and `ruff format --check`
  - `typecheck` — Run `pyright`
  - `unit_tests` — Run `pytest tests/` with coverage
  - `integration_tests` — Run `pytest tests/integration/` if the directory exists
  - `coverage_report` — Generate and display coverage report
  All sessions should use `uv` as the virtualenv backend where possible.

- **`src/<package_name>/`** — Source directory with `__init__.py` (package name derived from repo name, lowercased, underscores for hyphens)

- **`tests/`** — Test directory with `__init__.py` and `conftest.py`

- **`tests/integration/`** — Integration test directory with `__init__.py`

### 2. CI Pipeline

- **`.forgejo/workflows/ci.yml`** — Forgejo Actions workflow that:
  - Triggers on push to `master` and on pull requests
  - Uses a Python 3.11+ environment
  - Installs `uv` and `nox`
  - Runs all nox sessions: `lint`, `typecheck`, `unit_tests`, `coverage_report`
  - Reports test results

### 3. Contributing Guidelines

- **`CONTRIBUTING.md`** — Include:
  - Development setup instructions (clone, install with `uv`, run `nox`)
  - Coding standards (ruff for linting/formatting, pyright for type checking)
  - Commit message format (conventional commits: `feat:`, `fix:`, `docs:`, `refactor:`, `test:`, `chore:`)
  - Pull request process (branch from master, write tests, ensure CI passes, request review)
  - Testing requirements (all new code must have tests, maintain coverage)

### 4. Forgejo Labels

Create the following labels via the Forgejo API. Check existing labels first and skip any that already exist.

**State labels** (prefix `State/`):
- `State/Unverified` — color: `#808080` (gray) — Newly created, not yet verified
- `State/Verified` — color: `#0075ca` (blue) — Verified and ready for work
- `State/In Progress` — color: `#e4e669` (yellow) — Currently being worked on
- `State/In Review` — color: `#a2eeef` (cyan) — In code review
- `State/Paused` — color: `#d4c5f9` (lavender) — Work paused

**Priority labels** (prefix `Priority/`):
- `Priority/Critical` — color: `#b60205` (dark red)
- `Priority/High` — color: `#d93f0b` (red-orange)
- `Priority/Medium` — color: `#fbca04` (yellow)
- `Priority/Low` — color: `#0e8a16` (green)

**MoSCoW labels** (prefix `MoSCoW/`):
- `MoSCoW/Must` — color: `#b60205` (dark red)
- `MoSCoW/Should` — color: `#d93f0b` (red-orange)
- `MoSCoW/Could` — color: `#fbca04` (yellow)
- `MoSCoW/Won't` — color: `#808080` (gray)

**Type labels** (prefix `Type/`):
- `Type/Feature` — color: `#0075ca` (blue)
- `Type/Bug` — color: `#d73a4a` (red)
- `Type/Refactoring` — color: `#a2eeef` (cyan)
- `Type/Epic` — color: `#7057ff` (purple)
- `Type/Legendary` — color: `#ff6f00` (orange)

**Other labels**:
- `Blocked` — color: `#b60205` (dark red) — Blocked by external dependency or issue

### 5. Forgejo Milestones

Create milestones based on the product vision. At minimum:

- **Milestone 0: Project Setup** — Repository structure, CI pipeline, tooling configuration
- **Milestone 1: Core Foundation** — Core domain models, base architecture, fundamental features

Additional milestones should be derived from the product vision/architecture provided. Each milestone should have a clear description of its scope and goals.

### 6. Branch Protection

Protect the `master` branch with the following rules:
- Require CI status checks to pass before merging
- Require at least 1 review approval before merge
- Disallow direct pushes (all changes via PR)

Use the Forgejo API or `curl` commands to configure branch protection.

### 7. Directory Structure

Create the following directories (with `.gitkeep` files to ensure they are tracked):

- `docs/` — Project documentation
- `features/` — Behave BDD test features
- `features/steps/` — Behave step definitions
- `features/mocks/` — Mock data for Behave tests
- `robot/` — Robot Framework test suites
- `benchmarks/` — ASV benchmark definitions

## Process

1. Parse the inputs: repo owner, repo name, product vision, existing state
2. For each category above, check what already exists
3. Create only what is missing, in this order:
   a. Directory structure and project files (pyproject.toml, noxfile.py, src/, tests/)
   b. CI pipeline
   c. CONTRIBUTING.md
   d. Git commit and push all file changes
   e. Forgejo labels (via API)
   f. Forgejo milestones (via API)
   g. Branch protection (via API)
4. After all setup, post a summary comment on the session state issue (if an issue index is provided)

## Commit Strategy

- Make one commit per logical group: "chore: bootstrap project structure and CI pipeline"
- Push to `master` (this is initial setup, before branch protection is applied)
- Apply branch protection LAST so the setup commits can be pushed directly

## Return Value

Provide a structured report:

```
## Bootstrap Report

### Created
- <item 1>
- <item 2>
- ...

### Skipped (already existed)
- <item 1>
- <item 2>
- ...

### Errors
- <item>: <error description>
- ...
```

This report will be used by the calling agent to understand the project state going forward.
